コード例 #1
0
 private Order CreateTestOrderWithSoloRideInDatabase(RideStatus rideStatus = RideStatus.WaitingForAccept, OrderStatus orderStatus = OrderStatus.WaitingForAccept, int minutes = 0)
 {
     using (var context = _factory.CreateContext())
     {
         Customer customer = new Customer()
         {
             Name = "Name"
         };
         context.Customers.Add(customer);
         SoloRide soloRide = new SoloRide()
         {
             CustomerId           = customer.Id,
             DepartureTime        = DateTime.Now,
             ConfirmationDeadline = DateTime.Now.AddMinutes(-minutes),
             PassengerCount       = 0,
             CreatedOn            = DateTime.Now,
             Price            = 100,
             Status           = rideStatus,
             EndDestination   = new Address("City", 8200, "Street", 21),
             StartDestination = new Address("City", 8200, "Street", 21)
         };
         context.SoloRides.Add(soloRide);
         Order order = new Order()
         {
             Status = orderStatus,
             Price  = 100,
             Rides  = new List <Ride>()
         };
         order.Rides.Add(soloRide);
         context.Orders.Add(order);
         context.SaveChanges();
         return(order);
     }
 }
コード例 #2
0
        public async Task FindExpiredUnmatchedRides_SearchRides_FindExpectedAmoutn(RideStatus status, int expiredMinutse, int count)
        {
            var customer = new Customer();
            var soloRide = new SoloRide()
            {
                CustomerId           = customer.Id,
                DepartureTime        = DateTime.Now,
                ConfirmationDeadline = DateTime.Now.AddMinutes(-expiredMinutse),
                PassengerCount       = 0,
                CreatedOn            = DateTime.Now,
                Price            = 100,
                Status           = status,
                EndDestination   = new Address("City", 8200, "Street", 21),
                StartDestination = new Address("City", 8200, "Street", 21)
            };

            using (var context = _factory.CreateContext())
            {
                context.Add(customer);
                context.Add(soloRide);
                context.SaveChanges();
            }

            var rides = await _uut.RideRepository.FindExpiredUnmatchedRides();

            Assert.That(rides.Count, Is.EqualTo(count));
        }
コード例 #3
0
 public DriverRideDetailsQueryDto(IReadOnlyCollection <AddressDto> stops,
                                  MoneyDto income,
                                  CustomerDetailsDto customerDetails,
                                  RideStatus status) : base(income, customerDetails, status)
 {
     Stops = stops;
 }
コード例 #4
0
 protected DriverRideDetailsBaseDto(MoneyDto income,
                                    CustomerDetailsDto customerDetails,
                                    RideStatus status)
 {
     Income          = income;
     CustomerDetails = customerDetails;
     Status          = status;
 }
コード例 #5
0
 public Ride(Location source, ApplicationUser disp, RideVehicleType vehicle, ApplicationUser driver)
 {
     OrderDateTime = DateTime.Now;
     Source        = source;
     VehicleType   = vehicle;
     Dispatcher    = disp;
     Driver        = driver;
     Status        = RideStatus.Formed;
 }
コード例 #6
0
 public CustomerRideDetailsQueryDto(
     IReadOnlyCollection <RouteDto> routes,
     RideStatus status,
     MoneyDto price,
     DateTime?finishedDate,
     DriverDetailsDto driverDetails) : base(status, price)
 {
     Routes        = routes;
     FinishedDate  = finishedDate;
     DriverDetails = driverDetails;
 }
コード例 #7
0
ファイル: Ride.cs プロジェクト: ace333/TransportCompany
 public Ride(RideStatus status,
             Money income,
             int customerId,
             CustomerDetails customerDetails,
             params DestinationPoint[] stops)
 {
     Status          = status;
     Income          = income;
     CustomerId      = customerId;
     CustomerDetails = customerDetails;
     Stops           = stops;
 }
コード例 #8
0
ファイル: Ride.cs プロジェクト: krstic13/WP1718-PR113-2015
 public Ride(DateTime datumporudzbine, Location lokacija, string musterija, Location odrediste, string vozac, double iznos, Comment komentar, RideStatus statusVoznje, string dispatcher, CARTYPE tipvozila)
 {
     DatumIVremePorudzbine = datumporudzbine;
     LokacijaPolazna       = lokacija;
     Musterija             = musterija;
     Odrediste             = odrediste;
     Vozac        = vozac;
     Iznos        = iznos;
     Komentar     = komentar;
     StatusVoznje = statusVoznje;
     Dispatcher   = dispatcher;
     TipVozila    = tipvozila;
 }
コード例 #9
0
        public Ride(RideStatus status, Coordinate coordinates, String name, int minimumAge, double minimumLength, TimeSpan duration,
                    int maxPersons) : base(Guid.NewGuid(), LocationType.RIDE)
        {
            Status        = status;
            Name          = name;
            MinimumAge    = minimumAge;
            MinimumLength = minimumLength;
            Duration      = duration;
            MaxPersons    = maxPersons;
            Coordinates   = coordinates;

            // todo: Let's change this later to a flexible setup
            //setEmployeeSkillRequirement(WorkplaceSkill.Control, 2);
            //setEmployeeSkillRequirement(WorkplaceSkill.Host, 3);
        }
コード例 #10
0
        private List <RideStatus> fetchRidetatus(SqlCommand cmd)
        {
            SqlConnection     con   = cmd.Connection;
            List <RideStatus> rlist = null;

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    rlist = new List <RideStatus>();
                    while (dr.Read())
                    {
                        RideStatus r = new RideStatus();
                        r.Id     = Convert.ToInt32(dr["Id"]);
                        r.Status = Convert.ToString(dr["Status"]);
                        rlist.Add(r);
                    }
                    rlist.TrimExcess();
                }
            }
            return(rlist);
        }
コード例 #11
0
        public override async Task <RideDTO> CreateAsync(RideDTO dtoObject)
        {
            using (var trans = this.UnitOfWork.DBContext.Database.BeginTransaction())
            {
                Customer customer = await this.UnitOfWork.CustomerRepository.GetByUserId(this.requestInfo.UserId);

                if (customer == null)
                {
                    customer = await this.UnitOfWork.CustomerRepository.Create(new Customer()
                    {
                        UserId = this.requestInfo.UserId
                    });
                }

                IEnumerable <Ride> rideEntities = await this.Repository.GetByCustomerId(customer.Id);

                if (rideEntities.Where(x => x.IsActive).Count() == 0)
                {
                    LocationLagLon sourceEntity      = null;
                    LocationLagLon destinationEntity = null;
                    Distance       rideDistance      = null;

                    if (dtoObject.Source != null)
                    {
                        sourceEntity = await this.UnitOfWork.LocationLagLonRepository.Create(dtoObject.Source.ConvertToEntity());
                    }

                    if (dtoObject.Destination != null)
                    {
                        destinationEntity = await this.UnitOfWork.LocationLagLonRepository.Create(dtoObject.Destination.ConvertToEntity());
                    }

                    if (dtoObject.Source != null && dtoObject.Destination != null)
                    {
                        DistanceUnit distanceUnit = await this.UnitOfWork.DistanceUnitRepository.GetByCode(Core.Constant.DistanceUnit.Kilometer);

                        if (distanceUnit != null)
                        {
                            rideDistance = await this.UnitOfWork.DistanceRepository.Create(new Distance()
                            {
                                UnitId        = distanceUnit.Id,
                                TotalDistance = (await CalculateDistance(dtoObject.Destination.Latitude, dtoObject.Destination.Longitude, dtoObject.Source.Latitude, dtoObject.Source.Longitude))
                            });
                        }
                    }

                    await this.UnitOfWork.SaveAsync();

                    RideStatus rideStatus = await this.UnitOfWork.RideStatusRepository.GetByCode(Core.Constant.RideStatus.Waiting);

                    dtoObject.SourceId       = sourceEntity.Id;
                    dtoObject.DestinationId  = destinationEntity.Id;
                    dtoObject.RideDistanceId = rideDistance.Id;
                    dtoObject.CustomerId     = customer.Id;
                    dtoObject.IsActive       = true;

                    if (rideStatus != null)
                    {
                        dtoObject.RideStatusId = rideStatus.Id;
                    }

                    dtoObject = await base.CreateAsync(dtoObject);

                    trans.Commit();

                    return(dtoObject);
                }
                else
                {
                    return(await this.CustomerHeartBeatAsync(dtoObject));
                }
            }
        }
コード例 #12
0
        public IEnumerable <Ride> Get([FromUri] GetRidesFilterDTO filter)
        {
            if (!UserPrincipal.IsLoged)
            {
                throw new HttpResponseException(HttpStatusCode.Unauthorized);
            }

            IEnumerable <Ride> rides = null;



            if (UserPrincipal.IsDispatcher)
            {
                if (filter.OnlyAssigned)
                {
                    rides = (uow.UserRepository.GetByID(UserPrincipal.CurrentUser.Id) as Dispatcher).Rides;
                }
                else
                {
                    rides = uow.RideRepository.Get();
                }
            }
            else if (UserPrincipal.IsDriver)
            {
                if (filter.OnlyAssigned)
                {
                    rides = (uow.UserRepository.GetByID(UserPrincipal.CurrentUser.Id) as Driver).Rides;
                }
                else
                {
                    rides = uow.RideRepository.Get().Where(r => r.Status == RideStatus.Created);
                }
            }
            else if (UserPrincipal.IsCustomer)
            {
                rides = (uow.UserRepository.GetByID(UserPrincipal.CurrentUser.Id) as Customer).Rides;
            }

            if (filter.StatusFilter != null)
            {
                RideStatus statusFilter = (RideStatus)filter.StatusFilter;
                rides = rides.Where(r => r.Status == statusFilter);
            }

            DateTime fromDate = filter.FromOrderDate == null ? DateTime.MinValue : (DateTime)filter.FromOrderDate;
            DateTime toDate   = filter.ToOrderDate == null ? DateTime.MaxValue : (DateTime)filter.ToOrderDate;

            int fromRate = filter.FromRate == null ? int.MinValue : (int)filter.FromRate;
            int toRate   = filter.ToRate == null ? int.MaxValue : (int)filter.ToRate;

            int fromPrice = filter.FromPrice == null ? int.MinValue : (int)filter.FromPrice;
            int toPrice   = filter.ToPrice == null ? int.MaxValue : (int)filter.ToPrice;

            rides = rides.Where(r => (r.Date >= fromDate && r.Date <= toDate) &&
                                (r.Amount >= fromPrice && r.Amount <= toPrice));

            if (filter.FromRate != null || filter.ToRate != null)
            {
                rides = rides.Where(r => (r.Comment != null && r.Comment.Rating >= fromRate && r.Comment.Rating <= toRate));
            }

            GetRidesFilterDTO drf = filter;

            if (UserPrincipal.IsDispatcher && drf != null)
            {
                if (drf.CustomerName != null)
                {
                    rides = rides.Where(r => r.Customer != null && r.Customer.FirstName != null && r.Customer.FirstName.Equals(drf.CustomerName));
                }
                if (drf.CustomerLastName != null)
                {
                    rides = rides.Where(r => r.Customer != null && r.Customer.LastName != null && r.Customer.LastName.Equals(drf.CustomerLastName));
                }

                if (drf.DriverName != null)
                {
                    rides = rides.Where(r => r.Driver != null && r.Driver.FirstName != null && r.Driver.FirstName.Equals(drf.DriverName));
                }
                if (drf.DriverLastName != null)
                {
                    rides = rides.Where(r => r.Driver != null && r.Driver.LastName != null && r.Driver.LastName.Equals(drf.DriverLastName));
                }
            }

            if (filter.SortFilter == RideFilterSort.ByDate)
            {
                rides = rides.OrderByDescending(r => r.Date.Ticks);
            }
            else if (filter.SortFilter == RideFilterSort.ByRate)
            {
                rides = rides.OrderByDescending(r => r.Comment == null ? int.MaxValue : r.Comment.Rating);
            }
            else if (filter.SortFilter == RideFilterSort.ByDistance && UserPrincipal.IsDriver)
            {
                Driver driver = uow.UserRepository.GetByID(UserPrincipal.CurrentUser.Id) as Driver;
                if (driver.Location != null)
                {
                    GeoCoordinate cord = new GeoCoordinate(driver.Location.X, driver.Location.Y);
                    rides = rides.OrderBy(r => new GeoCoordinate(r.StartLocation.X, r.StartLocation.Y).GetDistanceTo(cord));
                }
            }

            return(rides);
        }
コード例 #13
0
 public IEnumerable <Ride> GetRidesForDriver(RideStatus rideStatus, int vehicleTypeId)
 {
     return(Context.Rides.Include("Payment").Where(vt => vt.RideStatus == rideStatus && vt.VehicleTypeId == vehicleTypeId).ToList());
 }
コード例 #14
0
 public InvalidRideStatusException(RideStatus status, Guid rideId)
     : base($"Invalid ride status: '{status}' for ride with id: {rideId}")
 {
 }
コード例 #15
0
        public async Task FindOrdersWithExpiredRides_OrdersRideHasWaitingForAccept_OrderIsReturned(RideStatus rideStatus, OrderStatus orderStatus, int minutes, int count)
        {
            CreateTestOrderWithSoloRideInDatabase(rideStatus, orderStatus, minutes);

            var orders = await _uut.OrderRepository.FindOrdersWithExpiredRides();

            Assert.That(orders.Count, Is.EqualTo(count));
        }
コード例 #16
0
 public RideStatusEventArgs(RideStatus rideStatus)
 {
     CurrentRidestatus = rideStatus;
 }
コード例 #17
0
 public void Update(FailedRideForm f)
 {
     Comment = new Comment(f, Driver, this);
     Status  = RideStatus.Failed;
 }
コード例 #18
0
 public void Update(SuccesfulRideForm f)
 {
     Destination = new Location(f);
     Price       = f.Price;
     Status      = RideStatus.Successful;
 }
コード例 #19
0
 protected CustomerRideDetailsDtoBase(RideStatus status, MoneyDto price)
 {
     Price  = price;
     Status = status;
 }