public List <MaxFleetFactorRow> GetMaxFleetFactors()
        {
            if (!Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.DayOfWeek))
            {
                return(null);
            }

            var splitDaysOfWeek =
                Parameters[DictionaryParameter.DayOfWeek].Split(VehicleFieldRestrictions.Separator.ToCharArray())
                .Select(int.Parse)
                .ToList();

            var locations = LocationQueryable.GetLocations(DataContext, Parameters);
            var carGroups = CarGroupQueryable.GetCarGroups(DataContext, Parameters);
            var weekDays  = from wd in DataContext.WeekDays
                            where splitDaysOfWeek.Contains(wd.DayOfWeekId)
                            select wd.DayOfWeekId;

            var locationsAndGroups = from l in locations
                                     from cg in carGroups
                                     from wd in weekDays
                                     select new
            {
                LocationId  = l.dim_Location_id,
                CarGroupId  = cg.car_group_id,
                DayOfWeekId = wd
            };

            var rows = from lag in locationsAndGroups
                       join mff in DataContext.MaxFleetFactors on
                       new { lag.CarGroupId, lag.LocationId, lag.DayOfWeekId } equals
            new { mff.CarGroupId, mff.LocationId, mff.DayOfWeekId }
            into jmf
            from joinedMaxFleet in jmf.DefaultIfEmpty()
            join cg in DataContext.CAR_GROUPs on lag.CarGroupId equals cg.car_group_id
            join loc in DataContext.LOCATIONs on lag.LocationId equals loc.dim_Location_id
                select new MaxFleetFactorRow(lag.DayOfWeekId)
            {
                Country       = cg.CAR_CLASS.CAR_SEGMENT.COUNTRy1.country_description,
                Pool          = loc.CMS_LOCATION_GROUP.CMS_POOL.cms_pool1,
                LocationGroup = loc.CMS_LOCATION_GROUP.cms_location_group1,
                Location      = loc.location1,
                CarSegment    = cg.CAR_CLASS.CAR_SEGMENT.car_segment1,
                CarClass      = cg.CAR_CLASS.car_class1,
                CarGroup      = cg.car_group1,
                LastChangedOn = joinedMaxFleet == null ? (DateTime?)null : joinedMaxFleet.UpdatedOn,
                LastChangedBy = joinedMaxFleet == null ? string.Empty : joinedMaxFleet.UpdatedBy,
                NonRevenue    = joinedMaxFleet == null ?  (double?)null : joinedMaxFleet.NonRevPercentage,
                Utilization   = joinedMaxFleet == null ? (double?)null : joinedMaxFleet.UtilizationPercentage,
            };
            var returned = rows.ToList();

            return(returned);
        }
        public void UpdateMaxFleetFactors(double?nonRevPercent, double?utilizationPercent)
        {
            if (!Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.DayOfWeek))
            {
                return;
            }

            var splitDaysOfWeek =
                Parameters[DictionaryParameter.DayOfWeek].Split(VehicleFieldRestrictions.Separator.ToCharArray())
                .Select(int.Parse)
                .ToList();

            var locations = LocationQueryable.GetLocations(DataContext, Parameters);
            var carGroups = CarGroupQueryable.GetCarGroups(DataContext, Parameters);
            var weekDays  = from wd in DataContext.WeekDays
                            where splitDaysOfWeek.Contains(wd.DayOfWeekId)
                            select wd.DayOfWeekId;

            var locationsAndGroups = from l in locations
                                     from cg in carGroups
                                     from wd in weekDays
                                     select new
            {
                LocationId  = l.dim_Location_id,
                CarGroupId  = cg.car_group_id,
                DayOfWeekId = wd
            };


            var entriesToUpdate = from lag in locationsAndGroups
                                  join mff in DataContext.MaxFleetFactors on
                                  new { lag.CarGroupId, lag.LocationId, lag.DayOfWeekId } equals
            new { mff.CarGroupId, mff.LocationId, mff.DayOfWeekId }
            select mff;



            if (nonRevPercent.HasValue)
            {
                entriesToUpdate.ForEach(d => d.NonRevPercentage = nonRevPercent.Value);
            }

            if (utilizationPercent.HasValue)
            {
                entriesToUpdate.ForEach(d => d.UtilizationPercentage = utilizationPercent.Value);
            }

            entriesToUpdate.ForEach(d => d.UpdatedBy = ApplicationAuthentication.GetGlobalId());
            entriesToUpdate.ForEach(d => d.UpdatedOn = DateTime.Now);


            var entriesToCreate = from fullCs in locationsAndGroups
                                  join mff in DataContext.MaxFleetFactors on
                                  new { fullCs.LocationId, fullCs.CarGroupId, fullCs.DayOfWeekId }
            equals new { mff.LocationId, mff.CarGroupId, mff.DayOfWeekId }
            into joinedFleetFactors
            from fleetFactors in joinedFleetFactors.DefaultIfEmpty()
            where fleetFactors == null
                select new
            {
                LocationId    = fullCs.LocationId,
                CarGroupId    = fullCs.CarGroupId,
                DayOfWeekId   = fullCs.DayOfWeekId,
                NonRev        = nonRevPercent,
                Utilization   = utilizationPercent,
                LastChangedOn = DateTime.Now,
                LastChangedBy = ApplicationAuthentication.GetGlobalId()
            };
            var localEntities = from etc in entriesToCreate.AsEnumerable()
                                select new MaxFleetFactor
            {
                LocationId            = etc.LocationId,
                CarGroupId            = etc.CarGroupId,
                DayOfWeekId           = etc.DayOfWeekId,
                NonRevPercentage      = etc.NonRev,
                UtilizationPercentage = etc.Utilization,
                UpdatedOn             = DateTime.Now,
                UpdatedBy             = ApplicationAuthentication.GetGlobalId()
            };

            DataContext.MaxFleetFactors.InsertAllOnSubmit(localEntities);
            DataContext.SubmitChanges();
        }
Example #3
0
        public void UpdateMaxFleetFactors(double?nonRevPercent, double?utilizationPercent, int scenarioId)
        {
            if (!Parameters.ContainsValueAndIsntEmpty(DictionaryParameter.DayOfWeek))
            {
                return;
            }

            var splitDaysOfWeek =
                Parameters[DictionaryParameter.DayOfWeek].Split(VehicleFieldRestrictions.Separator.ToCharArray())
                .Select(int.Parse)
                .ToList();

            var locations = LocationQueryable.GetLocations(DataContext, Parameters);
            var carGroups = CarGroupQueryable.GetCarGroups(DataContext, Parameters);
            var weekDays  = from wd in DataContext.WeekDays
                            where splitDaysOfWeek.Contains(wd.DayOfWeekId)
                            select wd.DayOfWeekId;

            var locationsAndGroups = from l in locations
                                     from cg in carGroups
                                     from wd in weekDays
                                     select new
            {
                LocationId  = l.dim_Location_id,
                CarGroupId  = cg.car_group_id,
                DayOfWeekId = wd
            };

            var employeeId = ApplicationAuthentication.GetEmployeeId();
            var marsUserId = GetMarsUserId(employeeId);

            var updateParam = BuildSprocParameter();

            updateParam.ScenarioId            = scenarioId;
            updateParam.DayOfWeekIds          = Parameters[DictionaryParameter.DayOfWeek];
            updateParam.MarsUserId            = marsUserId;
            updateParam.NonRevPercentage      = (float?)nonRevPercent;
            updateParam.UtilizationPercentage = (float?)utilizationPercent;


            DataContext.UpdateMaxFleetFactors(updateParam.ScenarioId, updateParam.LocationId,
                                              updateParam.LocationGroupId
                                              , updateParam.PoolId, updateParam.LocationCountry, updateParam.CarGroupId,
                                              updateParam.CarClassId, updateParam.CarSegmentId, updateParam.OwningCountry,
                                              updateParam.DayOfWeekIds, updateParam.MarsUserId, updateParam.NonRevPercentage
                                              , updateParam.UtilizationPercentage);


            var entriesToCreate = from fullCs in locationsAndGroups
                                  join mff in DataContext.MaxFleetFactors.Where(d => d.MaxFleetFactorScenarioId == scenarioId) on
                                  new { fullCs.LocationId, fullCs.CarGroupId, fullCs.DayOfWeekId }
            equals new { mff.LocationId, mff.CarGroupId, mff.DayOfWeekId }
            into joinedFleetFactors
            from fleetFactors in joinedFleetFactors.DefaultIfEmpty()
            where fleetFactors == null
                select new
            {
                LocationId    = fullCs.LocationId,
                CarGroupId    = fullCs.CarGroupId,
                DayOfWeekId   = fullCs.DayOfWeekId,
                NonRev        = nonRevPercent,
                Utilization   = utilizationPercent,
                LastChangedOn = DateTime.Now,
                MarsUserId    = marsUserId
            };


            DataContext.SubmitChanges();
            var localEntities = (from etc in entriesToCreate.ToList()
                                 select new MaxFleetFactor
            {
                MaxFleetFactorScenarioId = scenarioId,
                LocationId = etc.LocationId,
                CarGroupId = etc.CarGroupId,
                DayOfWeekId = etc.DayOfWeekId,
                NonRevPercentage = etc.NonRev,
                UtilizationPercentage = etc.Utilization,
                UpdatedOn = DateTime.Now,
                MarsUserId = etc.MarsUserId
            }).ToList();

            localEntities.ToList().BulkCopyToDatabase("MaxFleetFactor", DataContext, "fao");

            //DataContext.MaxFleetFactors.InsertAllOnSubmit(localEntities);
            DataContext.SubmitChanges();
        }