/// <summary> /// get details /// </summary> /// <param name="id">user id</param> /// <returns></returns> // GET: User/Details/5 public ActionResult Details(int id) { using (UserM user = new UserM()) { return(View(user.GetById(id))); } }
/// <summary> /// get editing populated form /// </summary> /// <param name="id">id </param> /// <returns>editing form</returns> // GET: User/Edit/5 public ActionResult Edit(int id) { using (UserM user = new UserM()) { User finded = user.GetById(id); UserEditModel edit = new UserEditModel(); Util <User, UserEditModel> .Copy(finded, edit); ModelState.Clear(); return(View(edit)); } }
/// <summary> /// remove user /// </summary> /// <param name="id">id</param> /// <returns>redirect to index</returns> // GET: User/Delete/5 public ActionResult Delete(int id) { try { using (UserM user = new UserM()) { User finded = user.GetById(id); user.Delete(finded); } ViewBag.Message = "User was deleted ."; return(RedirectToAction("Index")); } catch { ViewBag.Message = "Your application description page."; return(View()); } }
/// <summary> /// removing user /// </summary> /// <param name="id">user id</param> /// <returns>user list view</returns> public ActionResult Delete(int id) { try { using (UserM user = new UserM()) { User finded = user.GetById(id); user.Delete(finded); } TempData["Message"] = "User was removed from system..."; return(RedirectToAction("Index")); } catch { TempData["Message"] = "Remove unfortunately has stopped..."; return(RedirectToAction("Index")); } }
public ActionResult Edit([Bind(Include = "IdNumber, FullName, BirthDate, Sex, Password, Email, Role")] UserEditModel user, HttpPostedFileBase upload, int id) { try { using (UserM model = new UserM()) { User orginUser = model.GetById(id); if (ModelState.IsValid) { // if (TryUpdateModel(orginUser)) Util <UserEditModel, User> .Copy(user, orginUser); if (upload != null && upload.ContentLength > 0) { model.UpdateWithImage(orginUser, upload); } else { model.Update(orginUser); } return(RedirectToAction("Index", "Home")); } } return(View()); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } catch (Exception e) { return(View(e.ToString())); } }