public bool Add(MapDto map) { if (!_maps.GetAll().Any(i => i.Users.Login == map.Login) && map.Width >= 0 && map.Height >= 0) { _maps.Add(new Maps { User_ID = _users.GetAll().First(i => i.Login == map.Login).ID, Height = map.Height, Width = map.Width }); _unitOfWork.Commit(); return true; } return false; }
public bool Update(MapDto map) { if (map.Width >= 0 && map.Height >= 0) { foreach (var item in _maps.GetAll().Where(i => i.Map_ID == map.Map_ID)) { item.User_ID = _users.GetAll().First(i => i.Login == map.Login).ID; item.Height = map.Height; item.Width = map.Width; } _unitOfWork.Commit(); return true; } return false; }
public ActionResult AddMap(MapViewModel mapModel) { List<string> errors; if (Session["val"] != null) { errors = ((string[])Session["val"]).ToList(); } else { errors = new List<string>(); } MapDto _mapDto = new MapDto(); _mapDto.Login = mapModel.viewModel.User_Login; _mapDto.Height = mapModel.viewModel.Height; _mapDto.Width = mapModel.viewModel.Width; if (_mapService.Add(_mapDto)) { errors.Add("Dodano mapę."); } else { errors.Add("Błąd. Spróbuj ponownie."); } Session["val"] = errors.ToArray<string>(); return RedirectToAction("Admin"); }