public static Db.Trip ApiToTripDb(Api.Trip trip) { return(new Db.Trip { Id = trip.Id, FreeSeatCount = trip.FreeSeatCount, Departure = trip.Departure, DestinationFromId = trip.DestinationFromId, DestinationToId = trip.DestinationToId, TravelTime = trip.TotalMinutes, BusId = trip.BusId, TicketPrice = trip.TicketPrice }); }
public async Task <Api.Trip> GetTripWithSeats(int id) { Repositories.BaseModels.Trip trip = await _tripRepo.GetOneIncludes(id); List <Ticket> tickets = await _ticketRepo.FindAllAsync(t => t.TripId == id); Api.Trip tripRet = ModelTransformHelper.TripDbToApi(trip); tripRet.FreeSeatCount = trip.Bus.SeatsCount - tickets.Count; foreach (var item in tickets) { tripRet.FreeSeats.Remove(item.SeatNumber); } return(tripRet); }
public async Task <Db.Trip> Create(Api.Trip trip) { var tripToAdd = ModelTransformHelper.ApiToTripDb(trip); try { _context.Add(tripToAdd); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException ex) { ex.Entries.Single().Reload(); _context.SaveChanges(); } return(tripToAdd); }
public async Task <ActionResult <Db.Trip> > Create([FromBody] Api.Trip trip) { if (ModelState.IsValid) { try { var tripAdded = await _tripService.Create(trip); return(Ok(tripAdded)); } catch (Exception ex) { return(BadRequest(ex.Message)); } } else { return(BadRequest(ModelState.Values)); } }
public async Task <ActionResult <Db.Trip> > Create(Api.Trip trip) { return(await _tripRepo.Create(trip)); }