Hi guys, I have been trying to Do the Customize Security part of the CRM Demo with no other tables in the database. The database gets Migrated/Scaffolded correctly, but the FirstName, LastName, and Picture are not being sent/wrote to the database. The Registration, and 2F work fine, (no FirstName, LastName, and Picture). and can change the password. Everything seems to match with the source code, the add and edit forms freeze and give an unable to parse error. Ive done the exercise with Sqlite and MsSql databases with the same results. Anybody else having this issue.
I went thru everything again, I get the error Cannot create user, Unable to parse the response, on the Add and Edit users, the registration page works but doesn't write the extended data to the database. Not sure what else to do. Thanks
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace UserApp.Models
{
public partial class ApplicationUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Picture { get; set; }
public string Phone { get; set; }
[NotMapped]
public string FullName => $"{FirstName} {LastName}";
}
}
using Microsoft.EntityFrameworkCore;
using UserApp.Models;
namespace UserApp.Data
{
public partial class AppDbContext
{
partial void OnModelBuilding(ModelBuilder builder)
{
builder.Entity<ApplicationUser>().ToTable("AspNetUsers");
}
}
}
using System;
using System.Linq;
using UserApp.Models;
namespace UserApp.Controllers
{
public partial class ApplicationUsersController
{
partial void OnUserUpdated(ApplicationUser user)
{
var item = context.Users.Where(u => u.Id == user.Id).FirstOrDefault();
if (user != null)
{
item.FirstName = user.FirstName;
item.LastName = user.LastName;
item.Picture = user.Picture;
item.Phone = user.Phone;
}
}
}
}
I'm not sure if I need the RadzenCRMService.Custom.cs, Im not making a CRM App, and dont have the CRM tables in the database. I'm just trying to customize the user management part of the exercise, to have a customized user manager template to start from. I've gone thru the source code multiple times, copy/pasted the code and can't get it to work.
I'm not seeing what step I missed, Ive gone thru this process about ten times now I dont know why this isn't working. I get the error:
Thanks.
Rob
fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
at UserApp4.Controllers.ApplicationUsersController.Post(ApplicationUser user) in C:\Users\Rob31\source\Projects\UA4\Controllers\ApplicationUsersController.cs:line 137
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
info: System.Net.Http.HttpClient.UserApp4.ClientHandler[101]
Received HTTP response headers after 95.5152ms - 500
info: System.Net.Http.HttpClient.UserApp4.LogicalHandler[101]
End processing HTTP request after 95.6309ms - 500
I just followed the instructions posted above by @korchev for customizing the ApplicationUser for just FirstName and LastName and it all worked as expected.
You might need to run the application in debug mode to find why user is not being passed thru.