public ActionResult EditUser() { var model = new RegisterViewModel(); if (ModelState.IsValid) { using (SBSVEntities e = new SBSVEntities()) { Data.User user = e.Users.Where(s => s.Email == User.Identity.Name).Select(s => s).FirstOrDefault(); if (user.Id == 0) { return View(); } else { model.Id = user.Id; model.UserName = user.UserName; model.Email = user.Email; model.Password = user.Password; model.ImageUrl = string.IsNullOrEmpty(user.ImageUrl) ? @Url.Content("~/Content/UserImage/Default_user.png") : user.ImageUrl; return View(model); } } } return View(model); }
public ActionResult EditUser(RegisterViewModel model) { if (ModelState.IsValid) { var applocation = @Url.Content("~/Content/UserImage/Default_user.png"); bool imageUploaded = false; if (model.Image != null) { imageUploaded = true; applocation = Url.Content("~/Content/UserImage/" + model.Email) + model.Image.FileName.Substring(model.Image.FileName.LastIndexOf(".")); var destinationUrl = Server.MapPath(applocation); if (System.IO.File.Exists(destinationUrl)) { System.IO.File.Delete(destinationUrl); } model.Image.SaveAs(destinationUrl); } using (SBSVEntities e = new SBSVEntities()) { Data.User user = e.Users.Where(s => s.Id == model.Id).Select(s => s).FirstOrDefault(); if (user != null) { user.Email = model.Email; user.UserName = model.UserName; user.Password = model.Password; if (imageUploaded || string.IsNullOrEmpty(user.ImageUrl)) user.ImageUrl = applocation; int result = e.SaveChanges(); if (result == 1) { return RedirectToAction("Login", "Home"); } } } } return View(model); }
public ActionResult Register(RegisterViewModel model) { if (ModelState.IsValid) { using (SBSVEntities e = new SBSVEntities()) { Data.User user = new Data.User(); user.Email = model.Email; user.UserName = model.UserName; user.Password = model.Password; e.Users.AddObject(user); int result = e.SaveChanges(); if (result == 1) { return RedirectToAction("Login"); } } } return View(model); }