public ActionResult Edit() { UserDomain currentUser = RepositoryUsers.GetMany(u => u.Email == User.Identity.Name).SingleOrDefault(); if (currentUser == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, string.Format("User {0} not found", User.Identity.Name)); } UserEditView userView = new UserEditView { Id = currentUser.Id, Email = currentUser.Email, ImageData = currentUser.ImageData, ImageMimeType = currentUser.ImageMimeType }; return View(userView); }
public ActionResult Edit(UserEditView model, HttpPostedFileBase file) { if (ModelState.IsValid) { UserDomain user = RepositoryUsers.GetById(model.Id); if (user == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest, string.Format("User {0} not found", User.Identity.Name)); } user.EditDate = DateTime.Now; user.Password = Crypto.HashPassword(model.Password); if (file != null) { user.ImageMimeType = file.ContentType; user.ImageData = new byte[file.ContentLength]; file.InputStream.Read(user.ImageData, 0, (file.ContentLength)); } RepositoryUsers.Update(user); try { RepositoryUsers.SaveChanges(); return RedirectToAction("Index", "Home"); } catch (Exception ex) { ModelState.AddModelError("", ex.Message); } } return View(); }