public PartialViewResult DeleteUser(int userID) { var user = _repository.FindUserByID(userID); var model = new AccountModel { UserID = user.ID, UserName = user.UserName, GroupID = user.GroupID, Photo = user.Photo }; return PartialView(model); }
public ActionResult DeleteUser(AccountModel model) { try { int userID = model.UserID; if (!string.IsNullOrEmpty(model.Photo)) { System.IO.File.Delete(root + model.Photo); } _repository.DeleteUser(userID); _repository.CommitChanges(); return RedirectToAction("Group", "User", new { groupID = model.GroupID }); } catch (Exception) { return RedirectToAction("Error", new { eID = 0 }); } }
public PartialViewResult EditUser(int userID) { var user = _repository.FindUserByID(userID); var model = new AccountModel { UserID = user.ID, DisplayName = user.DisplayName, FirstName = user.FirstName, LastName = user.LastName, Job = user.Job, Email = user.Email, YahooID = user.IM, SkypeID = user.Skype, Phone = user.Phone, Photo = user.Photo, GroupID = user.GroupID }; return PartialView(model); }
public ActionResult Setup(AccountModel model, HttpPostedFileBase file) { try { if (!ModelState.IsValid) { return View(model); } // tạo ra admin mới var newUser = new User { UserName = model.UserName, Password = Encrypt(model.Password), Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, Job = model.Job, IM = model.YahooID, Skype = model.SkypeID, Phone = model.Phone, GroupID = 1, // set to administrator group CreatedOnDate = DateTime.Now }; if (file != null) { if (file.ContentLength > 26214400) { return RedirectToAction("Error", new { eID = 6 }); } var dir = root + file.FileName; var ext = Path.GetExtension(file.FileName); if (!System.IO.File.Exists(dir)) { newUser.Photo = newUser.UserName + ext; file.SaveAs(dir); System.IO.File.Move(dir, root + newUser.UserName + ext); } else { return RedirectToAction("Error", new { eID = 7 }); } } _repository.AddUser(newUser); _repository.CommitChanges(); return RedirectToLogin(); } catch (Exception) { return RedirectToAction("Error", new { eID = 0 }); } }
public ActionResult Register(AccountModel model, HttpPostedFileBase file) { try { if (!ModelState.IsValid) { return RedirectToAction("Error", "Base", new { eID = 0 }); } var user = _repository.FindUserByUserName(model.UserName); if (user != null) { return RedirectToAction("Error", "Base", new { eID = 2 }); } string email = _repository.FindEmail(model.Email); if (!string.IsNullOrEmpty(email)) { return RedirectToAction("Error", "Base", new { eID = 3 }); } var newUser = new User { UserName = model.UserName, Password = Encrypt(model.Password), Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, DisplayName = model.DisplayName, Job = model.Job, IM = model.YahooID, Skype = model.SkypeID, Phone = model.Phone, GroupID = model.GroupID, CreatedByUserID = int.Parse(User.Identity.Name), CreatedOnDate = DateTime.Now }; if (file != null) { if (file.ContentLength > 26214400) { return RedirectToAction("Error", new { eID = 6 }); } var dir = root + file.FileName; var ext = Path.GetExtension(file.FileName); if (!System.IO.File.Exists(dir)) { newUser.Photo = newUser.UserName + ext; file.SaveAs(dir); System.IO.File.Move(dir, root + newUser.UserName + ext); } else { return RedirectToAction("Error", new { eID = 7 }); } } _repository.AddUser(newUser); _repository.CommitChanges(); return RedirectToAction("Group", "User", new { groupID = model.GroupID }); } catch (Exception) { return RedirectToAction("Error", new { eID = 0 }); } }