コード例 #1
0
        public List <OverviewGridItemHolder> GetForeignVehicleOverviewGrid()
        {
            var vehicles = BaseVehicleDataAccess.GetVehicleQueryable(Parameters, DataContext, true, true);

            vehicles = VehicleFieldRestrictions.RestrictByPredicament(vehicles, Parameters);


            if (Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.MinDaysNonRev))
            {
                var daysSinceLastRevenue = int.Parse(Parameters[DictionaryParameter.MinDaysNonRev]);
                vehicles = vehicles.Where(d => d.DaysSinceLastRevenueMovement >= daysSinceLastRevenue);
            }

            var activeOwningCountries = GetActiveOwningCountries();

            var returned      = new List <OverviewGridItemHolder>();
            var dict          = GetCountryDescriptionDictionary();
            var groupingLevel = GetGroupingLevel();

            foreach (var oc in activeOwningCountries)
            {
                var owningCountry = oc;

                IQueryable <LocationCount> filteredOwner = null;
                switch (groupingLevel)
                {
                case DictionaryParameter.LocationCountry:
                    filteredOwner = from v in vehicles
                                    where v.OwningCountry == owningCountry
                                    group v by v.LastLocationCode.Substring(0, 2)
                                    into g
                                    select new LocationCount
                    {
                        LocationGroupingId = g.Key, Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Pool:
                    filteredOwner = from v in vehicles
                                    join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                    where v.OwningCountry == owningCountry
                                    group l by l.CMS_LOCATION_GROUP.CMS_POOL.cms_pool_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Region:
                    filteredOwner = from v in vehicles
                                    join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                    where v.OwningCountry == owningCountry
                                    group l by l.OPS_AREA.ops_region_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.LocationGroup:
                    filteredOwner = from v in vehicles
                                    join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                    where v.OwningCountry == owningCountry
                                    group l by l.cms_location_group_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Area:
                    filteredOwner = from v in vehicles
                                    join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                    where v.OwningCountry == owningCountry
                                    group l by l.ops_area_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Location:
                    filteredOwner = from v in vehicles
                                    join l in DataContext.LOCATIONs on v.LastLocationCode equals l.location1
                                    where v.OwningCountry == owningCountry
                                    group l by l.dim_Location_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;
                }



                var gvItem = new OverviewGridItemHolder
                {
                    CountryId             = oc,
                    CountryName           = dict[oc],
                    ForeignVehiclesHolder = new List <LocationIdHolder>()
                };


                if (filteredOwner != null)
                {
                    var filteredLocalList = filteredOwner.ToList();
                    foreach (var fo in filteredLocalList)
                    {
                        gvItem.ForeignVehiclesHolder.Add(new LocationIdHolder
                        {
                            LocationId    = fo.LocationGroupingId,
                            OwningCountry = owningCountry,
                            VehicleCount  = fo.Count
                        });
                    }
                }

                returned.Add(gvItem);
            }



            foreach (var gv in returned)
            {
                gv.ForeignVehiclesHolder.Add(new LocationIdHolder {
                    LocationId      = TotalString
                    , LocationName  = TotalString
                    , VehicleCount  = gv.ForeignVehiclesHolder.Sum(d => d.VehicleCount)
                    , OwningCountry = null
                });
            }

            return(returned);
        }
コード例 #2
0
        public List <OverviewGridItemHolder> GetReservationOverviewGrid()
        {
            var reservations = RestrictReservation();

            reservations = from r in reservations
                           where r.PickupLocation.location1.Substring(0, 2) != r.ReturnLocation.location1.Substring(0, 2)
                           select r;

            var returnCountries = reservations.Select(d => d.ReturnLocation.location1.Substring(0, 2)).Distinct().ToList();



            var returned      = new List <OverviewGridItemHolder>();
            var dict          = GetCountryDescriptionDictionary();
            var groupingLevel = GetGroupingLevel();

            foreach (var ac in returnCountries)
            {
                var returnCountry = ac;

                IQueryable <LocationCount> filteredOwner = null;
                switch (groupingLevel)
                {
                case DictionaryParameter.LocationCountry:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.location1.Substring(0, 2)
                                    into g
                                    select new LocationCount
                    {
                        LocationGroupingId = g.Key, Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Pool:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.CMS_LOCATION_GROUP.cms_pool_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Region:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.OPS_AREA.ops_region_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.LocationGroup:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.cms_location_group_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Area:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.ops_area_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;

                case DictionaryParameter.Location:
                    filteredOwner = from r in reservations
                                    where r.ReturnLocation.location1.Substring(0, 2) == returnCountry
                                    group r by r.PickupLocation.dim_Location_id
                                    into g
                                    select new LocationCount {
                        LocationGroupingId = g.Key.ToString(), Count = g.Count()
                    };
                    break;
                }



                var gvItem = new OverviewGridItemHolder
                {
                    CountryId             = ac,
                    CountryName           = dict[ac],
                    ForeignVehiclesHolder = new List <LocationIdHolder>()
                };


                if (filteredOwner != null)
                {
                    var filteredLocalList = filteredOwner.ToList();
                    foreach (var fo in filteredLocalList)
                    {
                        gvItem.ForeignVehiclesHolder.Add(new LocationIdHolder
                        {
                            LocationId    = fo.LocationGroupingId,
                            OwningCountry = returnCountry,
                            VehicleCount  = fo.Count
                        });
                    }
                }

                returned.Add(gvItem);
            }

            foreach (var gv in returned)
            {
                gv.ForeignVehiclesHolder.Add(new LocationIdHolder
                {
                    LocationId    = VehicleOverviewDataAccess.TotalString,
                    LocationName  = VehicleOverviewDataAccess.TotalString,
                    VehicleCount  = gv.ForeignVehiclesHolder.Sum(d => d.VehicleCount),
                    OwningCountry = null
                });
            }

            return(returned);
        }