Пример #1
0
 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
     });
 }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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));
            }
        }
Пример #5
0
 public async Task <ActionResult <Db.Trip> > Create(Api.Trip trip)
 {
     return(await _tripRepo.Create(trip));
 }