public async Task <IActionResult> EditAdmin(Guid id) { var model = new EditAdminModel(); await model.LoadByIdAsync(id); return(View(model)); }
public async Task <IActionResult> EditAdmin( [Bind(nameof(EditAdminModel.Id), nameof(EditAdminModel.FullName), nameof(EditAdminModel.Email), nameof(EditAdminModel.DateOfBirth), nameof(EditAdminModel.PhoneNumber), nameof(EditAdminModel.Gender), nameof(EditAdminModel.Address), nameof(EditAdminModel.ProfileImage))] EditAdminModel model) { if (ModelState.IsValid) { try { model.ImageUrl = UploadedFile(model); await model.UpdateAsync(); model.Response = new ResponseModel("Admin Updated successful.", ResponseType.Success); return(RedirectToAction("Index")); } catch (DuplicationException ex) { model.Response = new ResponseModel(ex.Message, ResponseType.Failure); _logger.LogError(ex.Message); } catch (Exception ex) { model.Response = new ResponseModel("Admin Update failured.", ResponseType.Failure); _logger.LogError(ex.Message); } } return(View(model)); }
private string UploadedFile(EditAdminModel model) { string uniqueFileName = null; if (model.ProfileImage != null) { string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "ProfileImages"); uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfileImage.FileName; string filePath = Path.Combine(uploadsFolder, uniqueFileName); using (var fileStream = new FileStream(filePath, FileMode.Create)) { model.ProfileImage.CopyTo(fileStream); } } return(uniqueFileName); }
public ActionResult EditAdmin(int id) { var roles = _userRepository.GetAllUserRoles(); ViewBag.S = new SelectList(roles, "Id", "Name"); var user = _repository.GetById(id); var model = new EditAdminModel() { Id = id, UserName = user.Username, RoleId = user.UserRoles.First().Id, Email = user.Email, Mobile = user.Mobile }; return(View(model)); }
public ActionResult EditAdmin(EditAdminModel model) { var roles = _userRepository.GetAllUserRoles(); ViewBag.S = new SelectList(roles, "Id", "Name"); var user = _repository.GetById(model.Id); user.Username = model.UserName; user.Email = model.Email; user.Mobile = model.Mobile; user.Password = Encrypt.EncryptString(model.Password); user.UserRoles.Clear(); var role = _userRepository.GetUserRoleById(model.RoleId); user.UserRoles.Add(role); _userRepository.UpdateUser(user); Success(); return(View(model)); }