// GET: /Employee1/Edit/5 // [UserAuthorized] public ActionResult Edit(int id) { var objRegistrationRepository = new RegistrationRepository(); var objEntity = new RegistrationViewModel(); var objUpdateEntity = new RegistrationUpdateViewModel(); objEntity = objRegistrationRepository.Select(RegistrationFlags.SelectByID.GetHashCode(), new RegistrationViewModel() { RegistrationId = id }).FirstOrDefault(); if (objEntity == null) { this.Flash("error", "Failed to edit your details"); return(RedirectToAction("Index")); } objUpdateEntity.RegistrationId = objEntity.RegistrationId; objUpdateEntity.UserId = objEntity.UserId; objUpdateEntity.Name = objEntity.Name; objUpdateEntity.DateOfBirth = objEntity.DateOfBirth; objUpdateEntity.Gender = objEntity.Gender; objUpdateEntity.City = objEntity.City; objUpdateEntity.MobileNumber = objEntity.MobileNumber; return(View(objUpdateEntity)); }
// [UserAuthorized] public ActionResult Edit(int id, RegistrationUpdateViewModel objUpdateEntity) { var objRegistrationRepository = new RegistrationRepository(); if (ModelState.IsValid) { objUpdateEntity.Name = objUpdateEntity.Name.Trim(); objUpdateEntity.City = objUpdateEntity.City.Trim(); objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim(); objUpdateEntity.RegistrationId = id; var objEntity = new RegistrationViewModel() { RegistrationId = objUpdateEntity.RegistrationId, UserId = objUpdateEntity.UserId, Name = objUpdateEntity.Name, DateOfBirth = objUpdateEntity.DateOfBirth, Gender = objUpdateEntity.Gender, City = objUpdateEntity.City, MobileNumber = objUpdateEntity.MobileNumber }; objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { this.Flash("success", "Data updated successfully "); return(RedirectToAction("Index")); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("error", "Account failed to update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("warning", "It already exist"); } } return(View(objUpdateEntity)); }
public async Task <ActionResult> Update(string registerId) { var user = new CustomIdentityUser(); var roles = _roleManager.Roles.Select(r => new SelectListItem { Text = r.Name, Value = r.Name }).ToList(); var userInfo = await _userManager.FindByIdAsync(registerId); var userRolId = await _userManager.GetRolesAsync(userInfo); var model = new RegistrationUpdateViewModel() { UserRolId = userRolId.FirstOrDefault(), UserIdentity = userInfo, Rols = roles }; return(View(model)); }
public ActionResult ProfileEdit(int id, RegistrationUpdateViewModel objUpdateEntity) { var objRegistrationRepository = new RegistrationRepository(); string fileName = string.Empty; string oldFileName = string.Empty; if (ModelState.IsValid) { #region FileUpload if (objUpdateEntity.UploadPhoto != null) { fileName = Guid.NewGuid().ToString() + Path.GetExtension(objUpdateEntity.UploadPhoto.FileName); oldFileName = objUpdateEntity.PhotoName; objUpdateEntity.PhotoName = fileName; } #endregion objUpdateEntity.FirstName = objUpdateEntity.FirstName.Trim(); objUpdateEntity.LastName = objUpdateEntity.LastName.Trim(); objUpdateEntity.PhotoName = objUpdateEntity.PhotoName; objUpdateEntity.Location = objUpdateEntity.Location.Trim(); objUpdateEntity.MobileNumber = objUpdateEntity.MobileNumber.Trim(); objUpdateEntity.RegistrationId = id; var objEntity = new RegistrationViewModel() { RegistrationId = objUpdateEntity.RegistrationId, UserId = objUpdateEntity.UserId, FirstName = objUpdateEntity.FirstName, LastName = objUpdateEntity.LastName, PhotoName = objUpdateEntity.PhotoName, DateOfBirth = objUpdateEntity.DateOfBirth, Gender = objUpdateEntity.Gender, Location = objUpdateEntity.Location, MobileNumber = objUpdateEntity.MobileNumber }; objEntity = objRegistrationRepository.Update(RegistrationFlags.UpdateByID.GetHashCode(), objEntity); if (objEntity.Result == ResultFlags.Success.GetHashCode()) { #region FileUpload //delete old file //file name if (objUpdateEntity.UploadPhoto != null) { if (!string.IsNullOrEmpty(objUpdateEntity.UploadPhoto.FileName)) { ApplicationHelpers.DeleteFile(Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), oldFileName)); } string path = Path.Combine(Server.MapPath(ApplicationConstant.UPLOADED_USER_PHOTO_PATH), fileName); // WebImage.Save() objUpdateEntity.UploadPhoto.SaveAs(path); } #endregion this.Flash("success", "My Profile updated successfully "); //reload admin profile SessionWrapper.UserAccount = null; AccountRepository objAccountRepository = new AccountRepository(); objAccountRepository.SetAccountByUser(objEntity.UserId); return(RedirectToAction("Dashboard", "User")); } else if (objEntity.Result == ResultFlags.Failure.GetHashCode()) { this.Flash("Error", "My Profile failed to update"); } else if (objEntity.Result == ResultFlags.Duplicate.GetHashCode()) { this.Flash("Warning", "It already exist"); } } return(View(objUpdateEntity)); }