/// <summary> /// Регистрация /// </summary> /// <param name="user"></param> public bool Registration(UsersDTO user) { try { Users UserDAL = new Users(); UserDAL.Name = user.Name; UserDAL.Login = user.Login; UserDAL.Password = user.Password; UserDAL.RegistrationDate = DateTime.Now; UserDAL.Avatar = user.Avatar; if (Data.Registration(UserDAL) == true) return true; else throw new ValidationException("Ваш запрос не был обработан", ""); } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }
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=""></param> public IEnumerable<UsersDTO> GetUsers() { try { List<UsersDTO> Users = new List<UsersDTO>(); var UsersDAL = Data.GetUsers(); foreach (var u in UsersDAL) { UsersDTO user = new UsersDTO(); user.UserID = u.UserID; user.Login = u.Login; user.Name = u.Name; user.RegistrationDate = u.RegistrationDate; user.TypeID = u.TypeID; user.UserType = u.UserType; user.Avatar = u.Avatar; Users.Add(user); } return Users; } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }
/// <summary> /// Изменить данные пользователя, для администратора /// </summary> /// <param name="user"></param> public bool ChangeUserType(UsersDTO user) { try { Users userDAL = new Users(); userDAL.UserID = user.UserID; userDAL.Login = user.Login; userDAL.Password = user.Password; userDAL.Name = user.Name; userDAL.RegistrationDate = user.RegistrationDate; userDAL.TypeID = user.TypeID; userDAL.Avatar = user.Avatar; if (Data.ChangeUserType(userDAL) == true) return true; else throw new ValidationException("Ваш запрос не был обработан", ""); } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }
/// <summary> /// Последнее сообщение в теме, для администратора /// </summary> /// <param name="TopicID"></param> public UsersDTO LastMessageForAdmin(int TopicID) { try { UsersDTO Users = new UsersDTO(); var UserDAL = Data.LastMessageForAdmin(TopicID); Users.Name = UserDAL.Name; Users.RegistrationDate = UserDAL.RegistrationDate; return Users; } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }
/// <summary> /// Информация о пользователе в онлайне /// </summary> /// <param name="Login"></param> public UsersDTO GetCurentUser(string Login) { try { UsersDTO user = new UsersDTO(); var UsersDAL = Data.GetCurentUser(Login); user.UserID = UsersDAL.UserID; user.Name = UsersDAL.Name; user.Avatar = UsersDAL.Avatar; return user; } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }
/// <summary> /// Информация об определённом пользователе /// </summary> /// <param name="UserID"></param> public UsersDTO GetUserById(int UserID) { try { UsersDTO user = new UsersDTO(); var UsersDAL = Data.GetUserById(UserID); user.UserID = UsersDAL.UserID; user.Login = UsersDAL.Login; user.Password = UsersDAL.Password; user.Name = UsersDAL.Name; user.RegistrationDate = UsersDAL.RegistrationDate; user.TypeID = UsersDAL.TypeID; user.UserType = UsersDAL.UserType; user.Avatar = UsersDAL.Avatar; return user; } catch (ArgumentException ex) { throw new ValidationException(ex.Message, ex.ParamName); } }