public IActionResult Edit(int id) { var designation = _designationService.GetById(id); var model = new DesignationListingModel { Id = designation.Id, Code = designation.Code, Name = designation.Name }; return(View(model)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); if (ModelState.IsValid) { //For Profile Image var uniqueFileName = GetUniqueFileName(Input.ProfileImageUrl.FileName); var uploads = Path.Combine(hostingEnvironment.WebRootPath, "uploads"); var filePath = Path.Combine(uploads, uniqueFileName); Input.ProfileImageUrl.CopyTo(new FileStream(filePath, FileMode.Create)); //end var empDesignation = _designationService.GetById(Input.DesignationId); var user = new ApplicationUser { UserName = Input.UserName, Email = Input.Email, Designation = empDesignation, IsActive = true, MemberSince = Input.MemberSince, ProfileImageUrl = uniqueFileName, DesignationName = empDesignation.Name }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }