public async Task <IActionResult> GetReservations() { try { var ret = await service.GetReservationsAsync(User.Identity.Name); if (ret != null) { var res = new List <ReservationParameter>(); foreach (var a in ret) { var temp = new ReservationParameter(); temp.Flight = mapper.Map <FlightResource>(a.AirlineTickets.First().Flight); temp.Airline = mapper.Map <AirlineResource>(a.AirlineTickets.First().Airline); if (a.AirlineTickets.First().Airline.Ratings.Count > 0) { temp.Airline.Rating = a.AirlineTickets.First().Airline.Ratings.Sum(i => i.Rate) / a.AirlineTickets.First().Airline.Ratings.Count; } else { temp.Airline.Rating = 0; } temp.Tickets = mapper.Map <ICollection <TicketParameter> >(a.AirlineTickets); foreach (var b in temp.Tickets) { b.Passport = ""; } res.Add(temp); } return(Ok(res)); } else { return(BadRequest("Something went wrong")); } } catch { return(StatusCode(500)); } }
public async Task <IActionResult> AddReservation(ReservationParameter flightReservation) { if (flightReservation.Tickets == null || flightReservation.Tickets.Count() == 0) { return(BadRequest(new { Message = "Tickets have to be supplied." })); } try { var ret = await service.Add(flightReservation.Tickets, flightReservation.InvestingPoints); if (ret.Success) { return(Ok(true)); } else { return(BadRequest(new { Message = ret.Message })); } } catch { return(StatusCode(500)); } }