public void Update(User user, String name, String pass, String mail) { if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(pass) || String.IsNullOrEmpty(mail) || user == null) throw new ArgumentException(ERROR_UPDATE_USER); user.Name = name; user.Password = pass; user.EMail = mail; }
public Comment Create(User user, News publication, String content) { if (String.IsNullOrEmpty(content) || user == null) throw new ArgumentException(ERROR_CREATE_COMMENT); Comment comment = new Comment() { Owner = user, Content = content, Publication = publication, DatePublication = DateTime.Now, CommentId = Guid.NewGuid() }; _database.Comments.Add(comment); return comment; }
public News Create(User user, String title, String content, String category, byte[] image = null) { if (String.IsNullOrEmpty(title) || String.IsNullOrEmpty(content) || user == null) throw new ArgumentException(ERROR_CREATE_NEWS); News news = new News() { Title = title, Content = content, Owner = user, Category = category, Image = image, DatePublication = DateTime.Now, NewsId = Guid.NewGuid() }; _database.News.Add(news); return news; }
public User Create(String name, String pass, String mail) { if (String.IsNullOrEmpty(name) || String.IsNullOrEmpty(pass) || String.IsNullOrEmpty(mail)) throw new ArgumentException(ERROR_CREATE_USER); User user = new User() { Name = name, Password = MD5Hash.GetMD5Hash(pass), EMail = mail, DateRegistration = DateTime.Now, UserId = Guid.NewGuid() }; _database.Users.Add(user); return user; }
public ActionResult Register(User user) { if (ModelState.IsValid) { using (UnitOfWork unit = new UnitOfWork()) { UserRepository userRep = new UserRepository(unit.DataContext); User u = userRep.GetUserByName(user.Name); if (u != null) { ViewBag.Message = "Пользователь с таким именем уже есть"; return View(user); } UserService userServ = new UserService(unit.DataContext); userServ.Create(user.Name, user.Password, user.EMail); unit.Commit(); Session["LoginUserID"] = user.UserId; Session["LogedUserName"] = user.Name; ModelState.Clear(); user = null; ViewBag.Message = "Регистрация успешно завершена"; return RedirectToAction("Index"); } } return View(user); }
public ActionResult Login(User user) { if (ModelState.IsValid) { using (UnitOfWork unit = new UnitOfWork()) { UserRepository userRep = new UserRepository(unit.DataContext); var authUser = userRep.GetUserByNameAndPass(user.Name, user.Password); if (authUser != null) { Session["LoginUserID"] = authUser.UserId.ToString(); Session["LogedUserName"] = authUser.Name; return RedirectToAction("Index"); } } } return View(user); }
public void Delete(User user) { if (user == null) throw new ArgumentException(ERROR_DELETE_USER); _database.Users.Remove(user); }