// // GET: /Account/EditUser public ActionResult EditUser() { var user = UserManager.FindByEmail(User.Identity.GetUserId()); if (user != null) { var model = new UserModel { Id = user.Id, Name = user.Name, Age = user.Age, Image = user.Image }; return View(model); } return RedirectToAction("Login", "Account"); }
public ActionResult EditUser(UserModel model, HttpPostedFileBase uploadImage) { var user = UserManager.FindByEmail(User.Identity.Name); if (user != null) { user.Name = model.Name; user.Age = model.Age; if (ModelState.IsValid && uploadImage != null) { byte[] imageData = null; using (var binaryReader = new BinaryReader(uploadImage.InputStream)) { imageData = binaryReader.ReadBytes(uploadImage.ContentLength); } user.Image = imageData; } var result = UserManager.Update(user); if (result.Succeeded) { return RedirectToAction("UserInfo", "Account"); } else { ModelState.AddModelError("", "Something going wrong"); } } else { ModelState.AddModelError("", "User not found"); } return View(model); }