public ActionResult ChangeUserType(UsersViewModel user) { try { ModelState.Remove("ConfirmPassword"); if ((ModelState.IsValid)) { UsersDTO UserBLL = new UsersDTO(); UserBLL.Name = user.Name; UserBLL.Login = user.Login; UserBLL.Password = user.Password; UserBLL.UserID = user.UserID; UserBLL.TypeID = user.TypeID; UserBLL.Avatar = user.Avatar; UserBLL.RegistrationDate = user.RegistrationDate; Data.ChangeUserType(UserBLL); return RedirectToAction("UsersList", "Home"); } else return View(user); } catch (ValidationException ex) { ModelState.AddModelError("DalError", ex.Message); return View(user); } }
public ActionResult Registration(UsersViewModel user) { try { if ((ModelState.IsValid) && (user.Password == user.ConfirmPassword)) { UsersDTO UserBLL = new UsersDTO(); UserBLL.Name = user.Name; UserBLL.Login = user.Login; UserBLL.Password = user.Password; UserBLL.Avatar = user.Avatar; Data.Registration(UserBLL); return RedirectToAction("Index"); } if (user.Password != user.ConfirmPassword) { ModelState.AddModelError("WrongConfirmPassword", "Пароли на совпадают."); return View(user); } else return View(user); } catch (ValidationException ex) { ModelState.AddModelError("DalError", ex.Message); return View(user); } }
/// <summary> /// Изменение информации о пользователе /// </summary> /// <param name="UserID"></param> public ActionResult ChangeUserType(int UserID) { try { var UserBLL = Data.GetUserById(UserID); UsersViewModel user = new UsersViewModel(); user.UserID = UserBLL.UserID; user.Login = UserBLL.Login; user.Password = UserBLL.Password; user.Name = UserBLL.Name; user.RegistrationDate = UserBLL.RegistrationDate; user.TypeID = UserBLL.TypeID; user.UserType = UserBLL.UserType; user.Avatar = UserBLL.Avatar; return View(user); } catch (ValidationException ex) { ModelState.AddModelError("DalError", ex.Message); return View(UserID); } }
/// <summary> /// Список пользователей /// </summary> /// <param name=""></param> public ActionResult UsersList() { try { List<UsersViewModel> userList = new List<UsersViewModel>(); var UserBLL = Data.GetUsers(); foreach (var u in UserBLL) { UsersViewModel user = new UsersViewModel(); if (u.UserID != 1) { user.UserID = u.UserID; user.Login = u.Login; user.Name = u.Name; user.Avatar = u.Avatar; user.RegistrationDate = u.RegistrationDate; user.TypeID = u.TypeID; user.UserType = u.UserType; userList.Add(user); } } return View(userList); } catch (ValidationException ex) { return Content(ex.Message); } }