Exemple #1
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();
        }
        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();
        }
Exemple #3
0
        public void UpdateMinCommercialSegments(double newMinCommSegPercent, int scenarioId)
        {
            var comSegData  = CommercialSegmentQueryable.GetCommercialCarSemgents(DataContext, Parameters);
            var locations   = LocationQueryable.GetLocations(DataContext, Parameters);
            var carSegments = CarSegmentQueryable.GetCarSegments(DataContext, Parameters);

            var fullComSeg = from ccs in comSegData
                             from l in locations
                             from cs in carSegments
                             select new
            {
                LocationId   = l.dim_Location_id,
                CarSegmentId = cs.car_segment_id,
                ccs.CommercialCarSegmentId
            };

            var minCommIdsToUpdate = from fullCs in fullComSeg
                                     join mcs in DataContext.MinCommercialSegments.Where(d => d.MinCommercialSegmentScenarioId == scenarioId) on
                                     new { fullCs.LocationId, fullCs.CarSegmentId, fullCs.CommercialCarSegmentId }
            equals new { mcs.LocationId, mcs.CarSegmentId, mcs.CommercialCarSegmentId }
            select mcs;

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

            minCommIdsToUpdate.ForEach(d => d.Percentage = newMinCommSegPercent);
            minCommIdsToUpdate.ForEach(d => d.MarsUserId = marsUserId);
            minCommIdsToUpdate.ForEach(d => d.UpdatedOn  = DateTime.Now);



            var entriesToCreate = from fullCs in fullComSeg
                                  join mcs in DataContext.MinCommercialSegments.Where(d => d.MinCommercialSegmentScenarioId == scenarioId) on
                                  new { fullCs.LocationId, fullCs.CarSegmentId, fullCs.CommercialCarSegmentId }
            equals new { mcs.LocationId, mcs.CarSegmentId, mcs.CommercialCarSegmentId }
            into joinedComSeg
            from comSegFigures in joinedComSeg.DefaultIfEmpty()
            where comSegFigures == null
                select new
            {
                LocationId             = fullCs.LocationId,
                CarSegmentId           = fullCs.CarSegmentId,
                CommercialCarSegmentId = fullCs.CommercialCarSegmentId,
                Percentage             = newMinCommSegPercent,
                LastChangedOn          = DateTime.Now,
                MarsUserId             = marsUserId
            };


            var localEntities = from etc in entriesToCreate.AsEnumerable()
                                select new MinCommercialSegment
            {
                LocationId = etc.LocationId,
                MinCommercialSegmentScenarioId = scenarioId,
                CarSegmentId           = etc.CarSegmentId,
                CommercialCarSegmentId = etc.CommercialCarSegmentId,
                Percentage             = newMinCommSegPercent,
                UpdatedOn  = DateTime.Now,
                MarsUserId = marsUserId
            };

            DataContext.MinCommercialSegments.InsertAllOnSubmit(localEntities);
            DataContext.SubmitChanges();
        }