public async Task <IBLLActionResult> AddReservation(Reservation res) { var result = ValidateReservation(res); var freeRooms = await GetFreeRooms(res.FromDate, res.ToDate); if (!freeRooms.Contains(res.Room)) { result.AddError("Pokój zajęty w wyznaczonym terminie."); } if (res.FromDate < DateTime.Now) { result.AddError("Data początku rezerwacji już minęła."); } //Checking if customer is already in our database. var cust = await customerData.FindByEmail(res.Customer.Email); if (cust != null) { res.Customer = cust; res.CustomerId = cust.CustomerId; } var resCus = ValidateCustomer(res.Customer); foreach (var err in resCus.ErrorMessages) { result.AddError(err); } if (result.Succeeded) { try { reservationData.Create(res); await reservationData.CommitAllRepos(); } catch (DbUpdateException) { result.AddError("Błędne dane."); } } return(result); }