Exemplo n.º 1
0
        public async Task <bool> Update(Ride ride)
        {
            if (ride == null)
            {
                return(false);
            }
            if (ride.Id == null)
            {
                return(false);
            }
            if (ride.Id.Equals(""))
            {
                return(false);
            }
            Models.Ride oldRide = await RidersContext.Ride.Where(x => x.Id == ride.Id).SingleOrDefaultAsync();

            if (ride.From != null)
            {
                if (!ride.From.Equals(""))
                {
                    oldRide.From = ride.From;
                }
            }
            if (ride.To != null)
            {
                if (!ride.To.Equals(""))
                {
                    oldRide.To = ride.To;
                }
            }
            //RidersContext.Update(ride);
            await RidersContext.SaveChangesAsync();

            return(true);
        }
        private IEnumerable <Entities.Ride> MapJsonRides(IEnumerable <int> rides, Models.InputJson.Json inputJson)
        {
            IList <Entities.Ride> rideEntities = new List <Entities.Ride>();

            foreach (var rideId in rides)
            {
                Models.Ride jsonRide = inputJson.Rides.First(x => x.Id == rideId);

                Entities.Ride entityRide = new Entities.Ride
                {
                    Id               = rideId,
                    Date             = jsonRide.Date,
                    StartTime        = jsonRide.StartTime,
                    PlannedStartTime = jsonRide.PlannedStartTime,
                    DriverId         = jsonRide.Driver ?? 0,
                    Driver           = MapJsonDriver(jsonRide.Driver, inputJson),
                    PlannedDriverId  = jsonRide.PlannedDriver,
                    PlannedDriver    = MapJsonDriver(jsonRide.PlannedDriver, inputJson),
                    Stations         = MapJsonStations(jsonRide.Stations, inputJson).ToList(),
                    Cancelled        = jsonRide.Cancelled
                };

                rideEntities.Add(entityRide);
            }

            return(rideEntities);
        }
Exemplo n.º 3
0
 public async Task <IActionResult> PutRide([FromBody] Dto.RideForPut ride, [FromRoute] string id)
 {
     if (ride == null)
     {
         return(BadRequest());
     }
     Models.Ride RideToUpdate = new Models.Ride {
         Id = id, From = ride.From, To = ride.To
     };
     if (await Repo.Update(RideToUpdate))
     {
         return(Ok());
     }
     return(BadRequest());
 }
Exemplo n.º 4
0
        public async Task <ActionResult <Dto.RideForGet> > GetRide(string id)
        {
            if (id.Equals(""))
            {
                return(BadRequest());
            }
            Models.Ride ride = await Repo.GetById(id);

            if (ride == null)
            {
                return(BadRequest());
            }
            return(Ok(new Dto.RideForGet {
                Id = ride.Id, From = ride.From, To = ride.To
            }));
        }