public async Task <IActionResult> Create(ReservationInputModel model) { int ecenomyTickets = model.Passengers.Count(p => p.TicketType == TicketType.Economy); int bussinesTickets = model.Passengers.Count(p => p.TicketType == TicketType.Bussines); int availableEconomyTickets = flightService.AvailableEconomyTickets(model.FlightId); int availableBusinessTickets = flightService.AvailableBussinesTickets(model.FlightId); if (availableEconomyTickets < ecenomyTickets) { ModelState.AddModelError(string.Empty, $"There are only {availableEconomyTickets} economy tickets left."); } if (availableBusinessTickets < bussinesTickets) { ModelState.AddModelError(string.Empty, $"There are only {availableBusinessTickets} business tickets left."); } if (!ModelState.IsValid) { return(View(model)); } await reservationService.Create(model); await flightService.UpdateAvailableTickets(model.FlightId, ecenomyTickets, bussinesTickets); FlightViewModel flight = flightService.GetById <FlightViewModel>(model.FlightId); await SendConfirmationEmailsToPassengers(model.Passengers, flight); await SendEmailToClient(model.Client.Email, flight, model.Passengers); return(Redirect("/")); }