public async Task <IActionResult> EditProfile(UserEditProFileViewModel userEditProFileViewModel, IFormFile UserImage) { var user = _userService.GetUserById(userEditProFileViewModel.UserID); if (user == null) { ViewBag.error = "اطلاعات را درست وارد کنید"; return(View("Index", GetUserInfo())); } if (user.UserName != user.UserName) { if (_userService.UserNameIsExist(userEditProFileViewModel.UserName)) { ViewBag.error = "این نام کاربری وجود دارد"; return(View("Index", GetUserInfo())); } } if (user.UserEmail != userEditProFileViewModel.UserEmail) { if (_userService.UserEmialIsExist(userEditProFileViewModel.UserEmail)) { ViewBag.error = "این ایمیل وجود دارد"; return(View("Index", GetUserInfo())); } } if (userEditProFileViewModel.UserImage != null) { string imgName = TextTools.GenerateUniqCode() + Path.GetExtension(userEditProFileViewModel.UserImage.FileName);; string a = Directory.GetCurrentDirectory(); string upLoad = await ImageUploader.ImageUpload(a, "/wwwroot/PorojectImg/UserImage/", user.UserImage, imgName, userEditProFileViewModel.UserImage); if (upLoad != "1") { ViewBag.error = "خطا در اپلود تصویر"; return(View("Index", GetUserInfo())); } user.UserImage = imgName; } #region Update user.UserName = userEditProFileViewModel.UserName; user.UserFristName = userEditProFileViewModel.UserFristName; user.UserLastName = userEditProFileViewModel.UserLastName; user.UserEmail = userEditProFileViewModel.UserEmail; user.UserAbout = userEditProFileViewModel.UserAbout; user.UserBirthday = userEditProFileViewModel.UserBirthday; _userRepository.UpdateUser(user); _userRepository.SaveUser(); #endregion return(View("Index", GetUserInfo())); }
public UserinfoViewModel GetUserInfo() { UserinfoViewModel userinfoViewModel = new UserinfoViewModel(); ChangePasswordViewModel changePasswordViewModel = new ChangePasswordViewModel(); UserEditProFileViewModel userEditProFileViewModel = new UserEditProFileViewModel(); UserViewModel userViewModel = new UserViewModel(); var user = _userService.GetUserById(Convert.ToInt32(User.Identity.Name)); #region UuserModel userViewModel.UserFristName = user.UserFristName; userViewModel.UserLastName = user.UserLastName; userViewModel.UserEmail = user.UserEmail; userViewModel.UserEmailConfigurationDateTime = user.UserEmailConfigurationDateTime; userViewModel.UserBirthday = user.UserBirthday; userViewModel.UserImage = user.UserImage; userViewModel.UserAbout = user.UserAbout; userViewModel.UserRol = _userService.GetUserRolesTitle(user.UserID); userViewModel.UserIsActive = user.UserIsActive; userViewModel.UserDateTime = user.UserDateTime; #endregion #region UuserEditProFileViewModel userEditProFileViewModel.UserID = user.UserID; userEditProFileViewModel.UserFristName = user.UserFristName; userEditProFileViewModel.UserLastName = user.UserLastName; userEditProFileViewModel.UserName = user.UserName; userEditProFileViewModel.UserAbout = user.UserAbout; userEditProFileViewModel.UserEmail = user.UserEmail; userEditProFileViewModel.UserBirthday = user.UserBirthday; #endregion changePasswordViewModel.UserId = user.UserID; userinfoViewModel.UserEditProFileViewModel = userEditProFileViewModel; userinfoViewModel.UserViewModel = userViewModel; userinfoViewModel.ChangePasswordViewModel = changePasswordViewModel; return(userinfoViewModel); }