public IHttpActionResult Post(DriverJourneyViewModel model)
 {
     sbyte respCode;
     if ((respCode=_adapter.AddTrip(model)) == -1)
         return BadRequest("All the fields except Est. time of departure and arrival are required");
     else if (respCode == -2)
         return BadRequest("Date must be entered and must be in this format: yyyy-mm-ddThh:mm:ss");
     else if (respCode == -3)
         return BadRequest("Seats available cannot be empy and must be a number");
     else
         return Ok();
 }
Example #2
0
        //(AllTrips VIEW: Shown only for all users) ADD A JOURNEY FOR A SPECIFIC DRIVER
        public sbyte AddTrip(DriverJourneyViewModel trip)
        {
            if (trip == null || trip.Destination == "" || trip.Destination==null || trip.DeparturePoint == "" || trip.DeparturePoint==null)
                return -1;
            else if (trip.Date == null)
                return -2;
            else if (trip.SeatsAvailable == null)
                return -3;
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                DestinationCounter dc=db.DestinationsCounter.FirstOrDefault(x => x.CityName == trip.Destination);
                if (dc == null)
                {
                    db.DestinationsCounter.Add(new DestinationCounter()
                    {
                        CityName = trip.Destination,
                        NumTrips = 1
                    });
                }
                else
                    dc.NumTrips += 1;

                db.SaveChanges();

                db.DriverJourneys.AddOrUpdate(x=>x.Id,new DriverJourney()
                {
                    UserId = db.Users.FirstOrDefault(y => y.UserName == trip.Username).Id,
                    DestinationCounterId=db.DestinationsCounter.FirstOrDefault(y=>y.CityName==trip.Destination).Id,
                    Destination=trip.Destination,
                    DestLatitud=trip.DestLatitud,
                    DestLongitud=trip.DestLongitud,
                    DeparturePoint=trip.DeparturePoint,
                    SeatsAvailable = (byte)trip.SeatsAvailable,
                    Date=(DateTime)trip.Date,
                    ETD=trip.ETD,
                    ETA=trip.ETA

                });
                db.SaveChanges();
            }
            return 0;
        }
Example #3
0
 public DriverJourneyViewModel GetSingleTrip(int tripId)
 {
     DriverJourneyViewModel SingleTrip;
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
        DriverJourney uno = db.DriverJourneys.FirstOrDefault(x=> x.Id == tripId);
       SingleTrip = new DriverJourneyViewModel()
         {
             Id = uno.Id,
             Destination = uno.Destination,
             DeparturePoint= uno.DeparturePoint,
             DestLatitud = uno.DestLatitud,
             DestLongitud = uno.DestLongitud,
             Date = uno.Date,
           ETA=uno.ETA,
             ETD = uno.ETD,
        };
     }
     return SingleTrip;
 }
Example #4
0
 //(UserTrips VIEW: Shown only for drivers) EDIT A SPECIFIC JOURNEY FOR A SPECIFIC DRIVER
 public void EditTrip(DriverJourneyViewModel trip)
 {
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         db.DriverJourneys.AddOrUpdate(x=>x.Id,new DriverJourney(){
         Id=trip.Id,
         UserId=db.Users.FirstOrDefault(x=>x.UserName==trip.Username).Id,
         Destination=trip.Destination,
         DestLatitud=trip.DestLatitud,
         DestLongitud=trip.DestLongitud,
         DeparturePoint=trip.DeparturePoint,
         SeatsAvailable=(byte)trip.SeatsAvailable,
         Date = (DateTime)trip.Date,
         ETD=trip.ETD,
         ETA=trip.ETA
         });
         db.SaveChanges();
     }
 }
Example #5
0
 //(UserTrips VIEW: Shown only for drivers) DELETE A SPECIFIC JOURNEY FOR A SPECIFIC DRIVER
 //DriverJourneys should have a bool isDeleted, so if a driver deletes a journey, passengers can see that the trip has been canceled and not have it magically dissapear from the list of their upcoming trips. Also an email notification would be necessary.
 public void DeleteTrip(DriverJourneyViewModel trip)
 {
     using (ApplicationDbContext db = new ApplicationDbContext())
     {
         DriverJourney dj = db.DriverJourneys.FirstOrDefault(x => x.Id == trip.Id);
         dj.DestinationCounter.NumTrips -= 1;
         db.DriverJourneys.Remove(dj);
         db.SaveChanges();
     }
 }
 public IHttpActionResult Post(DriverJourneyViewModel trip)
 {
     _adapter.DeleteTrip(trip);
     return Ok();
 }