public int TotalBreakdowns(int id, List <Ride> ridesList = null)
        {
            RideRepository rideRepository = new RideRepository();
            List <Ride>    rides          = ridesList;
            Ride           ride           = null;

            if (rides is null)
            {
                ride = rideRepository.GetRide(id);
            }
            else
            {
                ride = rideRepository.GetRide(id, rides);
            }
            int breakdowns = 0;

            foreach (Report report in ride.Reports)
            {
                if (report.Status == Status.Broken)
                {
                    breakdowns++;
                }
            }

            return(breakdowns);
        }
        public List <Report> GetReportsForRide(int id)
        {
            RideRepository rideRepository = new RideRepository();

            Ride ride = rideRepository.GetRide(id);

            return(ride.Reports);
        }
Example #3
0
        public RideCategory GetMostBrokenCategory(List <Ride> ridesList = null)
        {
            CategoryRepository  categoryRepository = new CategoryRepository();
            RideRepository      rideRepository     = new RideRepository();
            ReportRepository    reportRepository   = new ReportRepository();
            List <RideCategory> categories         = categoryRepository.GetRideCategories();
            RideCategory        categoryToReturn   = null;
            int         breakdowns = 0;
            List <Ride> rides      = ridesList;

            foreach (RideCategory category in categories)
            {
                if (categoryToReturn is null)
                {
                    categoryToReturn = category;
                    if (rides is null)
                    {
                        breakdowns = reportRepository.TotalBreakdowns(rideRepository.GetMostBrokenRide(category.Id).Id);
                    }
                    else
                    {
                        breakdowns = reportRepository.TotalBreakdowns(rideRepository.GetMostBrokenRide(category.Id, rides).Id, rides);
                    }
                }
                else
                {
                    int categoryBreakdowns = 0;
                    if (rides is null)
                    {
                        Ride mostBrokenRide = rideRepository.GetMostBrokenRide(category.Id);
                        if (mostBrokenRide != null)
                        {
                            categoryBreakdowns = reportRepository.TotalBreakdowns(mostBrokenRide.Id);
                        }
                    }
                    else
                    {
                        Ride mostBrokenRide = rideRepository.GetMostBrokenRide(category.Id, rides);
                        if (mostBrokenRide != null)
                        {
                            categoryBreakdowns = reportRepository.TotalBreakdowns(mostBrokenRide.Id, rides);
                        }
                    }

                    if (categoryBreakdowns > breakdowns)
                    {
                        categoryToReturn = category;
                        breakdowns       = categoryBreakdowns;
                    }
                }
            }

            return(categoryToReturn);
        }
Example #4
0
        public Ride GetMostBrokenRide(int?categoryId = null, List <Ride> ridesList = null)
        {
            RideRepository   rideRepository   = new RideRepository();
            ReportRepository reportRepository = new ReportRepository();
            List <Ride>      rides            = ridesList;

            if (rides is null)
            {
                rides = rideRepository.GetRides();
            }
            Ride rideToReturn = null;
            int  breakdowns   = 0;

            foreach (Ride ride in rides)
            {
                if (rideToReturn is null)
                {
                    if (categoryId is null)
                    {
                        rideToReturn = ride;
                        breakdowns   = reportRepository.TotalBreakdowns(ride.Id, rides);
                    }
                    else if (ride.Category.Id == categoryId)
                    {
                        rideToReturn = ride;
                        breakdowns   = reportRepository.TotalBreakdowns(ride.Id, rides);
                    }
                }
                else
                {
                    int rideBreakdowns = reportRepository.TotalBreakdowns(ride.Id, rides);
                    if (rideBreakdowns > breakdowns)
                    {
                        if (categoryId is null)
                        {
                            rideToReturn = ride;
                            breakdowns   = rideBreakdowns;
                        }
                        else if (ride.Id == categoryId)
                        {
                            rideToReturn = ride;
                            breakdowns   = rideBreakdowns;
                        }
                    }
                }
            }

            return(rideToReturn);
        }
        public int DaysSinceLastRideBreakdown(int id, List <Ride> ridesList = null)
        {
            RideRepository rideRepository = new RideRepository();
            List <Ride>    rides          = ridesList;
            Ride           ride           = null;

            if (rides is null)
            {
                ride = rideRepository.GetRide(id);
            }
            else
            {
                ride = rideRepository.GetRide(id, rides);
            }
            int days = 0;

            DateTime today      = DateTime.Now.Date;
            Report   lastReport = null;

            foreach (Report report in ride.Reports)
            {
                if (report.Status == Status.Broken)
                {
                    if (lastReport is null)
                    {
                        lastReport = report;
                    }
                    else
                    {
                        if (report.ReportTime.Date > lastReport.ReportTime.Date)
                        {
                            lastReport = report;
                        }
                    }
                }
            }

            if (lastReport is null)
            {
                return(-1);
            }

            DateTime lastReportDate = lastReport.ReportTime.Date;

            days = (today - lastReportDate).Days;

            return(days);
        }
        public int?DaysSinceLastBreakdownOnRides(List <Ride> ridesList = null)
        {
            RideRepository rideRepository = new RideRepository();
            List <Ride>    rides          = ridesList;

            if (rides is null)
            {
                rides = rideRepository.GetRides();
            }
            Ride rideToReturn = null;
            int  days         = 0;

            foreach (Ride ride in rides)
            {
                int daysSinceBreakdown = DaysSinceLastRideBreakdown(ride.Id, rides);
                if (rideToReturn is null && daysSinceBreakdown != -1)
                {
                    days         = daysSinceBreakdown;
                    rideToReturn = ride;
                }
Example #7
0
        public Ride GetLastBrokenRide(List <Ride> ridesList = null)
        {
            RideRepository   rideRepository   = new RideRepository();
            ReportRepository reportRepository = new ReportRepository();
            List <Ride>      rides            = ridesList;

            if (rides is null)
            {
                rides = rideRepository.GetRides();
            }
            Ride rideToReturn  = null;
            int  lastBreakdown = 0;

            foreach (Ride ride in rides)
            {
                int rideLastBreakdown = reportRepository.DaysSinceLastRideBreakdown(ride.Id, rides);
                if (rideToReturn is null && rideLastBreakdown != -1)
                {
                    rideToReturn  = ride;
                    lastBreakdown = reportRepository.DaysSinceLastRideBreakdown(ride.Id, rides);
                }