예제 #1
0
        public IEnumerable <RideDto> GetRidesByDriver(string email)
        {
            IEnumerable <Ride> rides = _rideRepository.GetRidesByDriver(email);


            List <RideDto> dtoRide = new List <RideDto>();
            int            count   = 0;



            foreach (var ride in rides)
            {
                RouteDto route = _routeLogic.GetRouteById(ride.RouteId);
                dtoRide.Add(_mapper.Map <Ride, RideDto>(ride));
                AddressDto fromAddress = _addressLogic.GetAddressById(route.FromId);
                dtoRide[count].FromCountry = fromAddress.Country;
                dtoRide[count].FromCity    = fromAddress.City;
                dtoRide[count].FromStreet  = fromAddress.Street;
                dtoRide[count].FromNumber  = fromAddress.Number;
                AddressDto toAddress = _addressLogic.GetAddressById(route.ToId);
                dtoRide[count].ToCountry = toAddress.Country;
                dtoRide[count].ToCity    = toAddress.City;
                dtoRide[count].ToStreet  = toAddress.Street;
                dtoRide[count].ToNumber  = toAddress.Number;
                count++;
            }
            return(dtoRide);
        }
예제 #2
0
        public IEnumerable <RideDto> GetRidesByDriver(string email)
        {
            IEnumerable <Ride> rides = _rideRepository.GetRidesByDriver(email);

            List <RideDto> dtoRides = new List <RideDto>();

            var passengers = _passengerLogic.GetPassengersByDriver(email);

            var notes = _driverNoteLogic.GetNotesByDriver(email);

            List <UserDto> users = new List <UserDto>();

            foreach (var passenger in passengers.GroupBy(x => x.Email).Select(g => g.First()).ToList())
            {
                users.Add(_userLogic.GetUserByEmail(EmailType.LOGIN, passenger.Email));
            }

            foreach (var passenger in passengers)
            {
                var user = users.Single(x => x.Email == passenger.Email);
                passenger.FirstName = user.FirstName;
                passenger.LastName  = user.LastName;
                passenger.Phone     = user.Phone;
            }

            foreach (var ride in rides)
            {
                var dtoRide = _mapper.Map <Ride, RideDto>(ride);
                dtoRide.Route       = _routeLogic.GetRouteById(ride.RouteId);
                dtoRide.Route.Rides = null;
                var note = notes.FirstOrDefault(x => x.RideId == ride.RideId);
                if (note != null)
                {
                    dtoRide.Note = note.Text;
                }
                if (ride.RideDateTime < DateTime.Now.AddHours(-1))
                {
                    dtoRide.Finished = true;
                }
                dtoRide.Passengers = passengers.Where(x => x.RideId == ride.RideId).ToList();
                dtoRides.Add(dtoRide);
            }
            return(dtoRides.OrderBy(x => x, new CustomComparer()).ToList());
        }