public IActionResult Create() { var genders = this.gendersService.GetAll <GenderDropDownViewModel>(); var viewModel = new UserCreateInputModel { Genders = genders, }; return(this.View(viewModel)); }
public async Task <IActionResult> Create(UserCreateInputModel input) { if (!this.ModelState.IsValid) { var genders = this.gendersService.GetAll <GenderDropDownViewModel>(); input.Genders = genders; return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); var newUser = new ApplicationUser { BirthDate = input.BirthDate, FirstName = input.FirstName, LastName = input.LastName, PhoneNumber = input.PhoneNumber, GenderId = input.GenderId, UserName = input.Username, Email = input.Email, HotelId = user.HotelId, }; var result = await this.userManager.CreateAsync(newUser, input.Password); if (result.Succeeded) { var code = await this.userManager.GenerateEmailConfirmationTokenAsync(newUser); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = this.Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = newUser.Id, code = code }, protocol: this.Request.Scheme); await this.mailHelper.SendFromIdentityAsync( input.Email, "Confirm your registration", $"{newUser.FirstName} {newUser.LastName}", "You are receiving this email because we received a registration confirmation request.", HtmlEncoder.Default.Encode(callbackUrl), "If you did not request a registration confirmation, no further action is needed."); } switch (input.Role) { case GlobalConstants.ManagerRoleName: await this.userManager.AddToRoleAsync(newUser, GlobalConstants.ManagerRoleName); break; case GlobalConstants.ReceptionistRoleName: await this.userManager.AddToRoleAsync(newUser, GlobalConstants.ReceptionistRoleName); break; } return(this.RedirectToAction("Manager", "Hotels")); }