public bool Add(BanDto ban) { if (!_bans.GetAll().Any(i => i.Users.Login == ban.Login)) { try { _bans.Add(new Bans { User_ID = _users.GetAll().First(i => i.Login == ban.Login).ID, Description = ban.Description, Start_Date = DateTime.Now, Finish_Date = ban.Finish_Date }); _unitOfWork.Commit(); return true; } catch (Exception) { return false; } } return false; }
public bool Update(BanDto ban) { if (_bans.GetAll().Any(i => i.ID == ban.ID)) { try { foreach (var item in _bans.GetAll().Where(i => i.ID == ban.ID)) { item.User_ID = _users.GetAll().First(i => i.Login == ban.Login).ID; item.Description = ban.Description; item.Finish_Date = ban.Finish_Date; } _unitOfWork.Commit(); return true; } catch (Exception) { return false; } } return false; }
public ActionResult AddBan(BanViewModel banModel) { List<string> errors; if (Session["val"] != null) { errors = ((string[])Session["val"]).ToList(); } else { errors = new List<string>(); } BanDto _banDto = new BanDto(); _banDto.Login = banModel.viewModel.User_Login; _banDto.Description = banModel.viewModel.Description; _banDto.Finish_Date = banModel.viewModel.FinishDate; if (_banService.Add(_banDto)) { errors.Add("Zablokowano gracza."); } else { errors.Add("Błąd. Srpróbuj ponownie."); } Session["val"] = errors.ToArray<string>(); return RedirectToAction("Admin"); }