public ActionResult Index(USER UserSubmit, FormCollection form, HttpPostedFileBase Picture) { CustomPrincipal prin = (CustomPrincipal)User; UserSubmit.ACTIVE = prin.ACTIVE; if (ModelState.IsValid) { if (userModels.CheckEmailEdit(UserSubmit.EMAIL, prin.ID)) { USER user1 = userModels.GetItem(prin.ID); //upload file string picture_new = ""; string picture_old = ""; if (Picture != null && Picture.ContentLength > 0) { // create new file ImgUpload imgUpload = new ImgUpload(); var path = Server.MapPath("~/Assets/Upload/User/"); UserSubmit.PICTURE = imgUpload.Upload(Picture, path); picture_new = UserSubmit.PICTURE; picture_old = user1.PICTURE; } else { UserSubmit.PICTURE = user1.PICTURE; } UserSubmit.ID_ROLE = user1.ID_ROLE; if (userModels.EditItem(prin.ID, UserSubmit) > 0) { if (!picture_old.Equals("")) { // delete file old var dataFile = Server.MapPath("~/Assets/Upload/User/" + picture_old); ImgUpload imgUpload = new ImgUpload(); imgUpload.Delete(dataFile); } Session["mes"] = "Sửa thành công"; } else { if (!picture_new.Equals("")) { // delete file old var dataFile = Server.MapPath("~/Assets/Upload/User/" + picture_new); ImgUpload imgUpload = new ImgUpload(); imgUpload.Delete(dataFile); } Session["mes_er"] = "Sửa thất bại"; } } else { Session["mes_er"] = "Email đã tồn tại"; } } return(RedirectToAction("Index", "ProfileManager")); }
public ActionResult Edit(int id, USER UserE, FormCollection form, HttpPostedFileBase Picture) { CustomPrincipal prin = (CustomPrincipal)User; if (userModels.CheckEmailEdit(UserE.EMAIL, id)) { if (roleModels.GetItem(UserE.ID_ROLE).NAME.Equals(ConstanAppkey.ADMIN())) { if (!(id == prin.ID && prin.ROLE.Equals(ConstanAppkey.ADMIN()))) { ViewBag.ListRole = roleModels.GetAllItems(); return(View(UserE)); } } if (prin.ROLE.Equals(ConstanAppkey.ADMIN()) && id == prin.ID) { UserE.ID_ROLE = roleModels.GetItemName(ConstanAppkey.ADMIN()).ID; } if (this.Request.Form["ACTIVE"] != null) { UserE.ACTIVE = true; } else { UserE.ACTIVE = false; } if (ModelState.IsValid) { USER user1 = userModels.GetItem(id); //upload file string picture_new = ""; string picture_old = ""; if (Picture != null && Picture.ContentLength > 0) { // create new file ImgUpload imgUpload = new ImgUpload(); var path = Server.MapPath("~/Assets/Upload/User"); UserE.PICTURE = imgUpload.Upload(Picture, path); picture_new = UserE.PICTURE; picture_old = user1.PICTURE; } else { UserE.PICTURE = user1.PICTURE; } if (userModels.EditItem(id, UserE) > 0) { if (!picture_old.Equals("")) { // delete file old var dataFile = Server.MapPath("~/Assets/Upload/User/" + picture_old); ImgUpload imgUpload = new ImgUpload(); imgUpload.Delete(dataFile); } Session["mes"] = "Sửa thành công"; } else { if (!picture_new.Equals("")) { // delete file old var dataFile = Server.MapPath("~/Assets/Upload/User/" + picture_new); ImgUpload imgUpload = new ImgUpload(); imgUpload.Delete(dataFile); } Session["mes_er"] = "Sửa thất bại"; } return(RedirectToAction("Index", "UserManager")); } } else { ViewBag.message_er = "Sửa thất bại! Email đã tồn tại"; } ViewBag.ListRole = roleModels.GetAllItems(); return(View(UserE)); }