public IHttpActionResult addComment(CommentBase data) { lock (DB) { RideBase ride = DB.RideDb.ToList().Find(p => p.ID == data.ID); List <CommentBase> comment = DB.CommentDb.ToList(); if (!comment.Exists(p => p.RideID == data.ID)) { if (ride.Status == RideStatus.Canceled) { data.Stars = 0; } DB.CommentDb.Add(new CommentBase() { CommentDate = DateTime.Now.ToString(), Stars = data.Stars, Summary = data.Summary, OriginalPoster = AuthUser.Username, RideID = ride.ID }); ride.CommentID = data.ID; DB.SaveChanges(); return(Ok(DB.CommentDb.ToList().Find(p => p.RideID == data.ID))); } return(NotFound()); } }
public void DeleteRide(RideBase ride) { Requires.NotNull(ride); Requires.PropertyNotNegative(ride, "RideId"); using (var context = DataContext.Instance()) { var rep = context.GetRepository <RideBase>(); rep.Delete(ride); } }
public IHttpActionResult getFreeDrivers(int id) { try { lock (DB) { RideBase ride = DB.RideDb.ToList().Find(x => x.ID == id); List <Driver> drivers = new List <Driver>(); DB.DriverDb.ToList().ForEach(x => { CarBase car = DB.CarDb.ToList().Find(y => y.TaxiCarID == x.CarID); if (ride.CarType == car.CarType || ride.CarType == CarRole.Not_Specified) { if (!DB.RideDb.ToList().Exists(z => z.Status == RideStatus.Accepted && z.TaxiRiderID == id)) { drivers.Add(x); } } }); LocationBase location = DB.LocationDb.ToList().Find(x => x.ID == ride.Location.ID); List <Tuple <double, Driver> > freeDrivers = new List <Tuple <double, Driver> >(); drivers.ForEach(x => { x.Location = DB.LocationDb.ToList().Find(y => y.ID == x.Location.ID); double lentgh = Math.Abs (Math.Sqrt(Math.Pow((location.XCoordinate - x.Location.XCoordinate), 2) + Math.Pow((location.YCoordinate - x.Location.YCoordinate), 2))); freeDrivers.Add(new Tuple <double, Driver>(lentgh, x)); }); freeDrivers = freeDrivers.OrderByDescending(x => x.Item1).ToList(); int driverCount = freeDrivers.Count; drivers = new List <Driver>(); for (int i = 0; i < 5; i++) { if (driverCount == 0) { break; } drivers.Add(freeDrivers[i].Item2); driverCount--; } return(Ok(drivers)); } } catch { return(NotFound()); } }
public void UpdateRide(RideBase ride, int userId) { Requires.NotNull(ride); Requires.PropertyNotNegative(ride, "RideId"); ride.LastModifiedByUserID = userId; ride.LastModifiedOnDate = DateTime.Now; using (var context = DataContext.Instance()) { var rep = context.GetRepository <RideBase>(); rep.Update(ride); } }
static void Main(string[] args) { //User clicks button //User selects file to upload and app type //User selects continue. //Call single class to generate correct IRide class. RideBase rideBase = RideBase.CreateRideData(RideDataApp.IpBike, ""); //Upload file using IRide interface rideBase.ProcessFile(); }
public HttpResponseMessage Add(AddRideDTO data) { var ride = new RideBase { ModuleId = ActiveModule.ModuleID, UserId = UserInfo.UserID, Incoming = data.Incoming, Location = data.Location, PlacesAvailable = data.Places, Notes = data.Notes }; var newId = RideRepository.Instance.AddRide(ref ride, UserInfo.UserID); return(Request.CreateResponse(HttpStatusCode.OK, RideRepository.Instance.GetRide(ActiveModule.ModuleID, newId))); }
public int AddRide(ref RideBase ride, int userId) { Requires.NotNull(ride); Requires.PropertyNotNegative(ride, "ModuleId"); ride.CreatedByUserID = userId; ride.CreatedOnDate = DateTime.Now; ride.LastModifiedByUserID = userId; ride.LastModifiedOnDate = DateTime.Now; using (var context = DataContext.Instance()) { var rep = context.GetRepository <RideBase>(); rep.Insert(ride); } return(ride.RideId); }
public IHttpActionResult AddDestination(LocationBase data) { lock (DB) { int taxiDriverID = DB.DriverDb.ToList().Find(x => x.Username == AuthUser.Username).ID; RideBase currentRide = DB.RideDb.ToList().Find(x => x.TaxiRiderID == taxiDriverID && x.ID == currentRideID); LocationBase l = DB.LocationDb.ToList().Find(x => x.ID == currentRide.Destination.ID); l.Place = data.Place; l.StreetName = data.StreetName; l.ZipCode = data.ZipCode; l.XCoordinate = data.XCoordinate; l.YCoordinate = data.YCoordinate; DB.SaveChanges(); return(Ok()); } }
public IHttpActionResult AddComment(CommentBase data) { lock (DB) { RideBase ride = DB.RideDb.ToList().Find(x => x.TaxiRiderID == DB.DriverDb.ToList().Find(y => y.Username == AuthUser.Username).ID&& x.ID == currentRideID); List <CommentBase> comment = DB.CommentDb.ToList(); if (!comment.Exists(p => p.RideID == data.ID)) { DB.CommentDb.Add(new CommentBase() { CommentDate = DateTime.Now.ToString(), Stars = data.Stars, Summary = data.Summary, OriginalPoster = AuthUser.Username, RideID = currentRideID }); ride.CommentID = data.ID; DB.SaveChanges(); return(Ok()); } return(NotFound()); } }
public void TestMethod1(RideDataApp appType, string expectedClassType) { RideBase value = RideBase.CreateRideData(appType, ""); Assert.AreEqual(value.GetType().Name, expectedClassType); }