public async Task <IActionResult> AddForProd([FromBody] UserViewModel model) { // return a generic HTTP Status 500 (Server Error) // if the client payload is invalid. if (model == null) { return(new StatusCodeResult(500)); } // check if the Username/Email already exists var user = await UserManager.FindByEmailAsync(model.Email); if (user != null) { return(BadRequest("Email already exists.")); } var now = DateTime.Now; // create a new Item with the client-sent json data user = new ApplicationUser { SecurityStamp = Guid.NewGuid().ToString(), UserName = model.Email, Email = model.Email, CreatedDate = now, LastModifiedDate = now, FirstName = model.FirstName, LastName = model.LastName, MiddleName = model.MiddleName, NormalizedEmail = model.Email.ToUpper(), ProfilePhoto = null }; // Add the user to the Db with the choosen password await UserManager.CreateAsync(user, model.Password); // Remove Lockout and E-Mail confirmation user.EmailConfirmed = true; user.LockoutEnabled = false; // Add Role to user var userRole = new ApplicationUserRole { UserId = user.Id, RoleId = _accountRoleRepository.RetrieveByName(model.Role).Id }; _accountUserRoleRepository.Create(userRole); DbContext.SaveChanges(); // return the newly-created User to the client. return(Json(user.Adapt <UserViewModel>(), JsonSettings)); }