protected override void Dispose(bool disposing) { if (disposing) { db.Dispose(); } base.Dispose(disposing); }
public ActionResult Edit(User user) { if (ModelState.IsValid) { var pic = user.Photo; var folder = "~/Content/Users"; if (user.PhotoFile != null) { if (pic == null || pic == string.Empty) { pic = FilesHelper.GetNamePhoto(user.UserId); } else { pic = pic.Substring(16); } if (pic != null) { pic = FilesHelper.UploadPhoto(user.PhotoFile, pic, folder); pic = string.Format("{0}/{1}", folder, pic); } } user.Photo = pic; var db2 = new EcomerceDataContext(); var currenrUser = db2.Users.Find(user.UserId); if (currenrUser.UserName != user.UserName) { UsersHelper.UpdateUserName(currenrUser.UserName, user.UserName); } db2.Dispose(); db.Entry(user).State = EntityState.Modified; db.SaveChanges(); var respons = DBHelper.SaveChanges(db); if (!respons.Succeded) { ModelState.AddModelError(string.Empty, respons.Message); return(View(user)); } return(RedirectToAction("Index")); } ViewBag.CityId = new SelectList(CombosHelper.GetCities(user.DepartmentId), "CityId", "Name", user.CityId); ViewBag.CompanyId = new SelectList(CombosHelper.GetCompanies(), "CompanyId", "Name", user.CompanyId); ViewBag.DepartmentId = new SelectList(CombosHelper.GetDepartments(), "DepartmentId", "Name", user.DepartmentId); return(View(user)); }
public void Dispose() { userContext.Dispose(); db.Dispose(); }
public void Dispose() { db.Dispose(); }