CRUD not working with asp net core identityrole

I took a demo from one of the forums and tried to implement crud on asp net core identity but the insert operation is not working. I am using AspNetCore MVC with net6.0. here is my code.

public class AccountController : Controller

{

private readonly RoleManager roleManager;

public AccountController(RoleManager roleManager)

{

this.roleManager = roleManager;

}


public IActionResult UrlDatasource([FromBody] DataManagerRequest dm)

{

var DataSource = roleManager.Roles.ToList();

DataOperations operation = new DataOperations();

int count = DataSource.Count;

return Json(new { result = DataSource, DataSource.Count });

}


public async Task InsertAsync([FromBody] CRUDModel value)

{

if (ModelState.IsValid)

{

IdentityRole identityRole = new()

{

Name = value.Value.Name

};

var result = await roleManager.CreateAsync(identityRole);

if (result.Succeeded)

{

return Json(value.Value);

}

foreach (var error in result.Errors)

{

// show error

}

}

return Json(null);

}

}


Markup

<ejs-grid id="Grid" allowPaging="true" allowSorting="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">

                <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>

                <e-data-manager url="/Account/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Account/InsertAsync"></e-data-manager>

                <e-grid-columns>

                    <e-grid-column field="id" headerText="Role ID" isIdentity="true" isPrimaryKey=true></e-grid-column>

                    <e-grid-column field="name" headerText="Role Name"></e-grid-column>

                    <e-grid-column field="normalizedName" headerText="Normalized Name" allowEditing="false"></e-grid-column>

                </e-grid-columns>

            </ejs-grid>



Beside that I am using repository pattern and almost my entire project uses async/await calls. Where can I find a demo that demonstrates repository pattern?



1 Reply 1 reply marked as answer

JC Joseph Christ Nithin Issack Syncfusion Team June 20, 2022 06:55 PM UTC

Hi Amanuel,


  Greetings from Syncfusion support.


  Based on your query, we suspect that you are using async function for the insert url. By default, in EJ2 Grid the grid actions are performed as a synchronous process. Hence, the grid will not wait until the data is fetched from the server. This is the reason for the reported behavior. Hence we suggest you to remove the async function and use normal function for the insert action.


Please get back to us for further details.


Regards,

Joseph I.


Marked as answer
Loader.
Up arrow icon