public bool AddDealBuildingAdmin(DealBuildingDto dealDto) { if (_deals.GetAll().Any(i => i.Buildings.Alias == dealDto.BuildingName && ((i.Users.Login == dealDto.Login) || (i.Users1.Login == dealDto.Login)))) { _dealsBuildings.Add(new DealsBuildings { Deal_ID = dealDto.Deal_ID, Building_ID = _buildings.GetAll().First(i => i.Alias == dealDto.BuildingName).ID, User_ID = _users.GetAll().First(i => i.Login == dealDto.Login).ID, }); _unitOfWork.Commit(); return true; } return false; }
public bool UpdateDealBuildingAdmin(DealBuildingDto dealDto) { if (_deals.GetAll().Any(i => i.Buildings.Alias == dealDto.BuildingName && ((i.Users.Login == dealDto.Login) || (i.Users1.Login == dealDto.Login)))) { foreach (var item in _dealsBuildings.GetAll().Where(i => i.ID == dealDto.ID)) { item.Building_ID = _buildings.GetAll().First(i => i.Alias == dealDto.BuildingName).ID; item.Deal_ID = item.Deal_ID; item.User_ID = _users.GetAll().First(i => i.Login == dealDto.Login).ID; } _unitOfWork.Commit(); return true; } return false; }
public ActionResult AddDealBuilding(DealBuildingViewModel dealbModel) { List<string> errors; if (Session["val"] != null) { errors = ((string[])Session["val"]).ToList(); } else { errors = new List<string>(); } DealBuildingDto dealbDto = new DealBuildingDto(); dealbDto.BuildingName = dealbModel.viewModel.Building_Name; dealbDto.Login = dealbModel.viewModel.User_Login; dealbDto.Deal_ID = dealbModel.viewModel.Deal_ID; if(_dealService.AddDealBuildingAdmin(dealbDto)) { errors.Add("Dodano budynek do umowy."); } else { errors.Add("Błąd. Spróbuj ponownie."); } Session["val"] = errors.ToArray<string>(); return RedirectToAction("Admin"); }