Completed
Last Updated: 19 Jul 2021 10:34 by ADMIN
Alberto
Created on: 17 Jul 2021 01:06
Category: UI for Blazor
Type: Bug Report
1
Problem adding new record using Grid Component InCell Editing

Hi!

Im using a Grid component InCell Editing the OnDelete, OnUpdate handlers are working fine but OnCreate handler its not working. By the way im using a service to manage the CRUD operations as follows

 

Page Component

@page "/districts"
@using MVC.Services
@using MVC.Models
@using System.ComponentModel.DataAnnotations
@inject IDistrictService DistrictService
<h3>Districts</h3>
<TelerikGrid Data="@district" Sortable="true" EditMode="@GridEditMode.Incell"
             Height="500px"
             Pageable="true" PageSize=@PageSize
             OnUpdate=@UpdateItem OnDelete=@DeleteItem OnCreate=@CreateItem OnCancel="@OnCancelHandler">
    <GridToolBar>
        <GridCommandButton Command="Add" Icon="add">Add District</GridCommandButton>
    </GridToolBar>
    <GridColumns>
        <GridColumn Field="@(nameof(District.Id))" Editable="false" />
        <GridColumn Field="@(nameof(District.Description))" Title="Description" />
        <GridColumn Field="@(nameof(District.EnableApprovalWorkflow))" Title="Enable Approval Workflow" />
        <GridCommandColumn>
            <GridCommandButton Command="Delete" Icon="delete">Delete</GridCommandButton>
        </GridCommandColumn>
    </GridColumns>
</TelerikGrid>
@code {
    int PageSize = 15;
    IEnumerable<District> district;

    protected override async Task OnInitializedAsync()
    {
        await GetGridData();
    }
    async Task GetGridData()
    {
        district = await DistrictService.DistrictList();
    }
    async Task CreateItem(GridCommandEventArgs args)
    {
        District item = (District)args.Item;
        await DistrictService.DistrictInsert(item);
        await GetGridData();
    }

    void OnCancelHandler(GridCommandEventArgs args)
    {
        District item = (District)args.Item;
    }

    async Task DeleteItem(GridCommandEventArgs args)
    {
        District item = (District)args.Item;
        await DistrictService.DistrictDelete(item.Id);
        await GetGridData();
    }

    async Task UpdateItem(GridCommandEventArgs args)
    {
        District item = (District)args.Item;
        await DistrictService.DistrictUpdate(item);
        await GetGridData();
    }
}

Service Logic


using Dapper;
using Microsoft.Data.SqlClient;
using MVC.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVC.Services
{
    public class DistrictService : IDistrictService
    {
        private readonly SqlConnectionConfiguration _configuration;
        public DistrictService(SqlConnectionConfiguration configuration)
        {
            _configuration = configuration;
        }
        public async Task<bool> DistrictInsert(District district)
        {
            using (var conn = new SqlConnection(_configuration.Value))
            {
                var parameters = new DynamicParameters();
                parameters.Add("Description", district.Description, DbType.String);
                parameters.Add("EnableApprovalWorkflow", district.EnableApprovalWorkflow, DbType.Boolean);
                await conn.ExecuteAsync("spLookupDistrict_Insert", parameters, commandType: CommandType.StoredProcedure);
            }
            return true;
        }
        public async Task<IEnumerable<District>> DistrictList()
        {
            IEnumerable<District> districts;
            using (var conn = new SqlConnection(_configuration.Value))
            {
                districts = await conn.QueryAsync<District>("spLookupDistrict_List", commandType: CommandType.StoredProcedure);
            }
            return districts;
        }
        public async Task<IEnumerable<District>> DistrictSearch(string @Param)
        {
            var parameters = new DynamicParameters();
            parameters.Add("@Param", Param, DbType.String);
            IEnumerable<District> districts;
            using (var conn = new SqlConnection(_configuration.Value))
            {
                districts = await conn.QueryAsync<District>("spLookupDistrict_Search", parameters, commandType: CommandType.StoredProcedure);
            }
            return districts;
        }
        public async Task<District> District_GetOne(int @Id)
        {
            District district = new District();
            var parameters = new DynamicParameters();
            parameters.Add("@Id", Id, DbType.Int32);
            using (var conn = new SqlConnection(_configuration.Value))
            {
                district = await conn.QueryFirstOrDefaultAsync<District>("spLookupDistrict_GetOne", parameters, commandType: CommandType.StoredProcedure);
            }
            return district;
        }
        public async Task<bool> DistrictUpdate(District district)
        {
            using (var conn = new SqlConnection(_configuration.Value))
            {
                var parameters = new DynamicParameters();
                parameters.Add("Id", district.Id, DbType.Int32);

                parameters.Add("Description", district.Description, DbType.String);
                parameters.Add("EnableApprovalWorkflow", district.EnableApprovalWorkflow, DbType.Boolean);

                await conn.ExecuteAsync("spLookupDistrict_Update", parameters, commandType: CommandType.StoredProcedure);
            }
            return true;
        }
        public async Task<bool> DistrictDelete(int Id)
        {
            var parameters = new DynamicParameters();
            parameters.Add("@Id", Id, DbType.Int32);
            using (var conn = new SqlConnection(_configuration.Value))
            {
                await conn.ExecuteAsync("spLookupDistrict_Delete", parameters, commandType: CommandType.StoredProcedure);
            }
            return true;
        }
    }
}

Attached Files:
3 comments
ADMIN
Nadezhda Tacheva
Posted on: 19 Jul 2021 10:34

Hi Alberto,

I am glad to hear the issue was resolved and you are moving forward exploring Blazor. I will now mark the status of this post as "Completed".

Please let us know if you run across any other concerns. We will be happy to step in and assist.

Regards,
Nadezhda Tacheva
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Alberto
Posted on: 18 Jul 2021 19:52

Hello Marin,

 

Thank you very much for your support, after upgranding to the latest version everything its working fine.

Im learning and evaluating Blazor and the Telerik components to implement this tecnology in our company for some new projects.

 

Again thank you for your help!

Have a great day

 

Alberto

ADMIN
Marin Bratanov
Posted on: 17 Jul 2021 14:32

Hello Alberto,

I advise that you:

  1. upgrade to the latest (2.25.0 at the moment, with 2.26.0 expected in early August)
  2. test the sample from the documentation that uses the same pattern
  3. since it works for me, it should work for you and you can compare against it to find the difference causing the problem
    • I find it likely that there is an issue with the database insertion and later with retrieving that item from the database since that's the main difference between the two snippets
  4. if there is still an issue, please modify the sample from the documentation to showcase the Telerik component problem without any additional dependencies (such as models, databases, application logic and so on), then send it to us for review

 

 

Regards,
Marin Bratanov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.