public async Task <ActionResult> ChangeProfile(ChangeProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } ApplicationUser user = UserManager.FindById(User.Identity.GetUserId()); user.UserName = model.UserName; user.Email = model.Email; user.FirstName = model.FirstName; user.LastName = model.LastName; user.DisplayName = model.DisplayName; var result = await UserManager.UpdateAsync(user); //var result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); if (result.Succeeded) { user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); if (user != null) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeProfileSuccess })); } AddErrors(result); return(View(model)); }
public async Task <ActionResult> ChangeProfile(ChangeProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = UserManager.FindById(User.Identity.GetUserId()); if (user == null) { return(View()); } // Update model details user.FirstName = model.FirstName; user.LastName = model.LastName; user.Email = model.Email; user.DisplayName = model.FirstName + " " + model.LastName; var result = await UserManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeProfileSuccess })); } AddErrors(result); return(View(model)); }
public async Task <IHttpActionResult> EditProfile([FromBody] ChangeProfileViewModel newProfile) { if (User.Identity.GetUserId() == null) { return(this.Unauthorized()); } int userId = User.Identity.GetUserId <int>(); if (userId != newProfile.Id) { return(BadRequest("It's not your profile!")); } if ((await _uow.UserInfoService.GetUserById(userId)).IsBlocked) { return(BadRequest("Your account has been blocked.")); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } DTOUser profileEdit = AutoMapper.Mapper.Map <ChangeProfileViewModel, DTOUser>(newProfile); await _uow.UserInfoService.Update(profileEdit); return(Ok("Profile has been updated.")); }
public async Task <ActionResult> ChangeProfilePicAsync(ChangeProfileViewModel model) { TARUser currentUser = UserManager.FindById(User.Identity.GetUserId()); if (ModelState.IsValid) { if (model.ImageFile == null) { model.ImagePath = currentUser.ImagePath; } else { string fileName = Path.GetFileNameWithoutExtension(model.ImageFile.FileName); string extension = Path.GetExtension(model.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; model.ImagePath = "~/Content/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Content/Images/"), fileName); model.ImageFile.SaveAs(fileName); } currentUser.ImagePath = model.ImagePath; currentUser.DisplayName = model.Name; var manager = new UserManager <TARUser> (new UserStore <TARUser> (new TARDBContext())); context.Entry(currentUser).State = System.Data.Entity.EntityState.Modified; await context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(RedirectToAction("Index")); }
public IActionResult ChangeProfile(ChangeProfileViewModel model) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("SignIn", "Account")); } if (ModelState.IsValid) { using (IDbConnection connection = new MySqlConnection(connectionString)) { byte[] imageData = null; if (model.ProfilePicture != null) { using (var binaryReader = new BinaryReader(model.ProfilePicture.OpenReadStream())) { imageData = binaryReader.ReadBytes((int)model.ProfilePicture.Length); } } AccountControllerHelperMethods.ChangeProfile(connection, model, User.FindFirstValue(ClaimTypes.NameIdentifier), imageData); } } return(RedirectToAction("UserAccount")); }
// GET: /Manage/ChangeProfile public ActionResult ChangeProfile(ManageMessageId?message = null) { ViewBag.StatusMessage = message == ManageMessageId.ModifSuccess ? "Vos modifications ont été prises en compte." : message == ManageMessageId.Error ? "Une erreur s'est produite." : ""; var user = UserManager.Users.First(u => u.UserName == User.Identity.Name); // Dont let user edit another user if not Admin if ((user.UserName != User.Identity.Name) && (!User.IsInRole("Admin"))) { ModelState.AddModelError("", "You are not" + user.UserName); return(new HttpStatusCodeResult(System.Net.HttpStatusCode.Unauthorized)); } var model = new ChangeProfileViewModel(user); model.Pseudo = user.Pseudo; // [10028] ADD: UserName (ReadOnly) in Manage/ChangeProfile model.UserName = user.UserName; // [10028] model.Email = user.Email; return(View(model)); }
public ActionResult ChangeProfile(ChangeProfileViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var currentUserId = User.Identity.GetUserId(); using (var conn = new ApplicationDbContext()) { var user = conn.UserProfiles.SingleOrDefault(x => x.UserId == currentUserId); if (user == null) { user = conn.UserProfiles.Add(new UserProfile { UserId = currentUserId, FirstName = model.FirstName, LastName = model.LastName, Address = model.Address, PhoneNumber = model.PhoneNumber, WebSite = model.WebSite }); } else { conn.Entry(user).CurrentValues.SetValues(model); } conn.SaveChanges(); } return(RedirectToAction("Index", new { Message = "<b>Your profile has been updated.</b>" })); }
// //GET: /Manage/ChangeProfile public ActionResult ChangeProfile() { _userManager = HttpContext.GetOwinContext().GetUserManager <ApplicationUserManager>(); var userId = User.Identity.GetUserId(); if (userId == null) { return(RedirectToAction("Login", "AccountControler")); } else { ApplicationUser user = _userManager.FindByIdAsync(userId).Result; var model = new ChangeProfileViewModel(); model.FirstName = user.FirstName; model.LastName = user.LastName; model.UserName = user.UserName; model.CityId = user.CityId; model.PhoneNumber = user.PhoneNumber; //model.UserPhoto = user.UserPhoto; model.Cities = GetAllCities(); return(View(model)); } }
public async Task <IActionResult> EditUserProfile(ChangeProfileViewModel model, List <string> roles) { AppUser user = await _userManager.FindByIdAsync(model.UserID); if (user != null) { var userRoles = await _userManager.GetRolesAsync(user); var allRoles = _roleManager.Roles.ToList(); var addedRoles = roles.Except(userRoles); var removedRoles = userRoles.Except(roles); await _userManager.AddToRolesAsync(user, addedRoles); await _userManager.RemoveFromRolesAsync(user, removedRoles); user.Email = model.Email; user.UserName = model.Email; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(RedirectToAction("Index")); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } } return(NotFound()); }
public async Task <IActionResult> EditProfile(string id) { if (id == null) { return(View("Error")); } if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } AppUser user = await _userManager.FindByIdAsync(id); if (User.Identity.Name != user.UserName) { return(RedirectToAction("Error", "Home")); } ChangeProfileViewModel viewModel = new ChangeProfileViewModel() { Firstname = user.Firstname, Lastname = user.Lastname, Email = user.Email, Phone = user.PhoneNumber, Username = user.UserName, PhotoURL = user.PhotoURL }; return(View(viewModel)); }
public async Task <IActionResult> EditProfile(ChangeProfileViewModel changeProfileViewModel) { if (!ModelState.IsValid) { return(View(changeProfileViewModel)); } var user = await _db.SiteAdmins.FirstOrDefaultAsync(a => a.Email.Equals(User.Identity.Name)); user.Email = changeProfileViewModel.Email; if (!string.IsNullOrEmpty(changeProfileViewModel.CurrentPassword) && !string.IsNullOrEmpty(changeProfileViewModel.Password)) { var currentPassword = PasswordHelper.Hash(changeProfileViewModel.CurrentPassword); if (user.Password.Equals(currentPassword)) { user.Password = PasswordHelper.Hash(changeProfileViewModel.Password); } else { TempData["Error"] = "رمز عبور فعلی وارد شده صحیح نمی باشد"; return(RedirectToAction("EditProfile")); } } _db.SiteAdmins.Update(user); await _db.SaveChangesAsync(); await _accountService.LogoutAsync(); TempData["Success"] = "پروفایل شما با موفقیت ویرایش یافت. لطفا دوباره وارد شوید"; return(RedirectToAction("EditProfile")); }
public ActionResult Edit() { if (Session["UserId"] == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetUser aspnetuser = db.AspNetUsers.Find(Session["UserId"]); ChangeProfileViewModel changeProfile = new ChangeProfileViewModel(); if (aspnetuser == null) { return(HttpNotFound()); } changeProfile.UserProfile = UserProfile(aspnetuser); changeProfile.ChangePassword = new ChangePasswordViewModel { OldPassword = "", NewPassword = "", ConfirmPassword = "" }; if (aspnetuser.Country == null) { ViewBag.Country = "India"; } else { ViewBag.Country = aspnetuser.Country; } return(View(changeProfile)); }
public ActionResult Index(ChangeProfileViewModel viewModel) { var currentUserID = _authService.GetCurrentUser().ID; var profileDTO = Mapper.Map <ChangeProfileDTO>(viewModel); _profileService.ChangeProfile(currentUserID, profileDTO); return(RedirectToAction("Index")); }
public static ChangeProfileDto ToDto(this ChangeProfileViewModel source) { return(new ChangeProfileDto { Id = source.Id, ImageName = source.ImageName, FullName = source.FullName, PhoneNumber = source.PhoneNumber }); }
public ActionResult ChangeProfile() { AppUser user = _userManager.FindByName(HttpContext.User.Identity.Name); ChangeProfileViewModel model = new ChangeProfileViewModel(); model.FullName = user.FullName; model.BirthDate = user.BirthDate; model.Bio = user.Bio; return(View(model)); }
public ActionResult ChangeProfilePic() { TARUser model = UserManager.FindById(User.Identity.GetUserId()); ChangeProfileViewModel c = new ChangeProfileViewModel { Name = model.DisplayName }; return(PartialView("_ChangeProfilePic", c)); }
public ActionResult LichSu_MuaHang() { var session = (KhachHang)Session["Taikhoan"]; List <HoaDon> list = new List <HoaDon>(); if (session != null) { list = new ChangeProfileViewModel().ListByCustomerID(session.MaKH); } return(View(list)); }
// // GET: /Manage/ChangeUsername public ActionResult ChangeProfile() { ChangeProfileViewModel model = new ChangeProfileViewModel(); var user = UserManager.FindById(User.Identity.GetUserId()); model.FirstName = user.FirstName; model.LastName = user.LastName; model.Email = user.Email; return(View(model)); }
public ActionResult ChangeProfile() { var userId = User.Identity.GetUserId(); var user = db.Users.FirstOrDefault(p => p.Id == userId); var model = new ChangeProfileViewModel(); model.Name = user.Name; model.LastName = user.LastName; model.DisplayName = user.DisplayName; return(View(model)); }
public async Task <IActionResult> ChangeProfile(ChangeProfileViewModel model, IFormFile file) { var dto = model.ToDto(); var validationResult = _adminService.ChangeProfile_Validation(dto); if (validationResult.IsSuccess) { var uploadService = new ServiceResult <string>(false); if (file != null) { uploadService = _fileService.Upload(file, "Profile", 1024 * 200); } model.ImageName = uploadService.Data; if ((file != null && uploadService.IsSuccess) || file == null) { var serviceResult = _adminService.ChangeProfile(model.ToDto()); if (serviceResult.IsSuccess) { Swal(true, "عملیات با موفقیت انجام شد"); if (file != null && !string.IsNullOrEmpty(serviceResult.Data)) { _fileService.Delete(serviceResult.Data, "Profile"); } var user = _adminService.GetUserEntity(UserId); await _signInManager.SignOutAsync(); await _signInManager.SignInAsync(user, true); return(RedirectToAction(nameof(ChangeProfile))); } model.ImageName = serviceResult.Data; AddErrors(serviceResult); } else { Swal(false, uploadService.Errors.FirstOrDefault()); } } else { AddErrors(validationResult); } return(View(model)); }
public async Task <IActionResult> EditProfile() { var user = await _db.SiteAdmins .FirstOrDefaultAsync(a => a.Email.Equals(User.Identity.Name)); var profileViewModel = new ChangeProfileViewModel { Email = user.Email }; return(View(profileViewModel)); }
public IHttpActionResult ChangeProfile(ChangeProfileViewModel model) { var userId = model.ToServiceRequestModel().CurrentUserId.Value; var response = UserManager.ChangePassword(userId, model.OldPassword, model.NewPassword); if (response.Succeeded) { return(Ok()); } return(BadRequest(response.Errors.SingleOrDefault())); }
public ActionResult ChangeProfile(ChangeProfileViewModel model) { if (ModelState.IsValid) { var userId = User.Identity.GetUserId(); var dbUser = db.Users.FirstOrDefault(p => p.Id == userId); dbUser.Name = model.Name; dbUser.LastName = model.LastName; dbUser.DisplayName = model.DisplayName; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Edit(string btnSubmit, string hdnCountry, ChangeProfileViewModel aspnetuser) { try { var UserProfile = db.AspNetUsers.FirstOrDefault(x => x.Id == aspnetuser.UserProfile.Id); if (UserProfile == null) { return(HttpNotFound()); } if (btnSubmit == "Change Password") { IdentityResult result = UserManager.ChangePassword(aspnetuser.UserProfile.Id, aspnetuser.ChangePassword.OldPassword.ToString(), aspnetuser.ChangePassword.NewPassword.ToString()); if (result.Succeeded) { ViewBag.msg = "Password Changed Successfully."; aspnetuser.ChangePassword = new ChangePasswordViewModel { OldPassword = "", NewPassword = "", ConfirmPassword = "" }; } else { ViewBag.msg = ((string[])(result.Errors))[0]; } } else { UserProfile.PhoneNumber = aspnetuser.UserProfile.PhoneNumber; UserProfile.Email = aspnetuser.UserProfile.Email; UserProfile.City = aspnetuser.UserProfile.City; UserProfile.State = aspnetuser.UserProfile.State; UserProfile.Country = hdnCountry; UserProfile.PIN = aspnetuser.UserProfile.PIN; UserProfile.Address = aspnetuser.UserProfile.Address; db.SaveChanges(); ViewBag.msg = "Profile Updated Successfully."; } ViewBag.Country = hdnCountry; return(View(aspnetuser)); } catch (Exception) { ViewBag.Country = hdnCountry; ViewBag.msg = "Problem in Updating Profile."; return(View(aspnetuser)); } }
/// <summary> /// Change the profile. /// </summary> /// <param name="connection"></param> /// <param name="model"></param> /// <param name="userId"></param> /// <param name="imageData"></param> public static void ChangeProfile(IDbConnection connection, ChangeProfileViewModel model, string userId, byte[] imageData) { char?genderToPass = model.Gender == null ? (char?)null : (model.Gender == "Men" ? 'm' : 'f'); var p = new DynamicParameters(); p.Add("A_Id", userId); p.Add("A_UserName", model.User_Name); p.Add("A_FullName", model.FullName); p.Add("A_Gender", genderToPass); p.Add("A_Email", model.Email); p.Add("A_Bio", model.Bio); p.Add("A_WebSiteLink", model.WebSiteLink); p.Add("A_ProfilePicture", imageData, DbType.Binary); connection.Execute("UpdateUserProfile", p, commandType: CommandType.StoredProcedure); }
public ActionResult ChangeProfile(string Id) { var user = UserManager.Users.Single(x => x.Id == Id); var userVM = new ChangeProfileViewModel { BirthDay = user.BirthDay, LastName = user.LastName, FirstName = user.FirstName, IndexNumber = user.IndexNumber, PhoneNumber = user.PhoneNumber, UserPhoto = user.UserPhoto, Id = user.Id }; return(View(userVM)); }
public async Task <ActionResult> ChangeImage(ChangeProfileViewModel model) { try { if (!((model.UserImage == null) || model.UserImage.ContentType.Contains("image"))) { throw new ArgumentException("Fisierul selectat nu este o imagine"); } IdentityResult isChanged = new IdentityResult("Nu s-a putut modifica!"); if (!ModelState.IsValid) { return(View(model)); } var verifyUser = await UserManager.FindAsync(User.Identity.Name, model.Password); if (verifyUser != null) { System.IO.File.Delete(System.IO.Path.Combine(Server.MapPath($"~/images"), $"{verifyUser.UserName}.jpg")); if (model.UserImage != null) { string path = System.IO.Path.Combine(Server.MapPath($"~/images"), $"{verifyUser.UserName}.jpg"); model.UserImage.SaveAs(path); } return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeProfilePhotoSuccess })); } ModelState.AddModelError("Parola actuala", "Parola nu este corecta"); return(View(model)); } catch (NullReferenceException e) { logger.Error(e.ToString()); throw new NullReferenceException("Imaginea nu a putut fi gasita"); } catch (ArgumentException e) { logger.Error(e.ToString()); throw new ArgumentException("Fisierul ales nu este o imagine"); } catch (Exception e) { //if something else goes wrong logger.Error(e.ToString()); throw new Exception("Ceva nu a mers bine, va rugam reincercati. Daca problema persista contactati un administrator."); } }
public ActionResult Index() { var session = (KhachHang)Session["Taikhoan"]; var profile = new ChangeProfileViewModel(); if (session != null) { var entity = data.KhachHangs.Where(kh => kh.MaKH == session.MaKH).FirstOrDefault(); profile.HoTen = entity.HoTen; profile.TenDangNhap = entity.TenDangNhap; profile.DiaChi = entity.DiaChi; profile.SoDienThoai = entity.SoDienThoai; profile.Email = entity.Email; return(View(profile)); } return(View()); }
public ActionResult Create([Bind(Exclude = "UserPhoto")] ChangeProfileViewModel user) { if (!ModelState.IsValid) { return(View("ChangeProfile", user)); } byte[] imageData = null; if (Request.Files.Count > 0) { HttpPostedFileBase poImgFile = Request.Files["UserPhoto"]; using (var binary = new BinaryReader(poImgFile.InputStream)) { imageData = binary.ReadBytes(poImgFile.ContentLength); } } if (imageData.Count() < 1) { imageData = UserManager.Users.SingleOrDefault(x => x.Id == user.Id).UserPhoto; } var userInDb = UserManager.Users.SingleOrDefault(x => x.Id == user.Id); userInDb.FirstName = user.FirstName; userInDb.LastName = user.LastName; userInDb.IndexNumber = user.IndexNumber; userInDb.PhoneNumber = user.PhoneNumber; userInDb.BirthDay = user.BirthDay; userInDb.UserPhoto = imageData; var model = new IndexViewModel { FirstName = userInDb.UserName, LastName = userInDb.LastName, IndexNumber = userInDb.IndexNumber, Id = userInDb.Id, BirthDay = userInDb.BirthDay, PhoneNumber = userInDb.PhoneNumber, UserPhoto = imageData }; UserManager.Update(userInDb); return(View("Index", model)); }
public ActionResult ChangeProfile(ChangeProfileViewModel model) { if (ModelState.IsValid) { AppUser user = _userManager.FindByName(HttpContext.User.Identity.Name); user.FullName = model.FullName; user.BirthDate = model.BirthDate; user.Bio = model.Bio; IdentityResult result = _userManager.Update(user); if (result.Succeeded) { ViewBag.Message = "Profile updated successfully."; } else { ModelState.AddModelError("", "Error while saving profile."); } } return(View(model)); }