private void SaveAdditionPlan()
        {
            AdditionPlanEntity ape;

            using (var dataAccess = new BaseDataAccess())
            {
                ape = new AdditionPlanEntity
                {
                    Name = tbAdditionPlanName.Text,
                    MinComSegScenarioName        = ddlMinCommSeg.SelectedItem.Text,
                    MinComSegScenarioDescription = imgMinFleetDescription.ToolTip,
                    MaxFleetScenarioName         = ddlMaxFleetFactor.SelectedItem.Text,
                    MaxFleetScenarioDescription  = imgMaxFleetDescription.ToolTip,
                    WeeksCalculated  = int.Parse(tbWeeks.Text),
                    CurrentDate      = dataAccess.GetLastHistoryTimestamp(),
                    StartRevenueDate = dataAccess.MinCommercialDataDate(),
                    EndRevenueDate   = dataAccess.MinCommercialDataDate(),
                };
            }



            var additions = (List <AdditionEntity>)Session[AdditionPlanSessionHolder];

            if (additions == null)
            {
                return;
            }

            var minMaxValues = (List <WeeklyMaxMinValues>)Session[DemandGapDisplaySession];



            var countryId = int.Parse(ddlCountry.SelectedValue);

            using (var additionPlanDataAccess = new AdditionPlanDataAccess())
            {
                additionPlanDataAccess.CreateAdditionPlan(ape, additions, minMaxValues, countryId);
            }
            pnlGapFill.Visible = false;
        }
示例#2
0
        public void CreateAdditionPlan(AdditionPlanEntity ape
                                       , List <AdditionEntity> weeklyAdditions
                                       , List <WeeklyMaxMinValues> minMaxValues
                                       , int countryId)
        {
            var loggedOnEmployee = ApplicationAuthentication.GetEmployeeId();
            var marsUserId       = GetMarsUserId(loggedOnEmployee);
            var entityToCreate   = new AdditionPlan
            {
                Name = ape.Name,
                MinComSegScenarioName         = ape.MinComSegScenarioName,
                MinComSegSccenarioDescription = ape.GetMinComSegScenarioDescription(),
                MaxFleetScenarioName          = ape.MaxFleetScenarioName,
                MaxFleetScenarioDescription   = ape.GetMaxFleetScenarioDescription(),
                StartRevenueDate = ape.GetStartRevenue(),
                EndRevenueDate   = ape.GetEndRevenue(),
                CurrentDate      = ape.GetCurrentDate(),
                DateCreated      = DateTime.Now,
                WeeksCalculated  = ape.GetWeeksCalculated(),
                CountryId        = countryId,
                //AdditionPlanEntries = additionPlanEntries,
                //AdditionPlanMinMaxValues = minMaxValueEntities,
                //CreatedBy = createdBy,
                MarsUserId = marsUserId
            };

            DataContext.AdditionPlans.InsertOnSubmit(entityToCreate);

            DataContext.SubmitChanges();

            var additionPlanId = entityToCreate.AdditionPlanId;

            var maxMinValues = from mmv in minMaxValues
                               select new AdditionPlanMinMaxValue
            {
                AdditionPlanId        = additionPlanId,
                Year                  = (short)mmv.Year,
                Week                  = (byte)mmv.WeekNumber,
                CarGroupId            = mmv.GetCarGroupId(),
                LocationId            = mmv.GetLocationId(),
                Rank                  = mmv.RankFromRevenue,
                TotalFleet            = mmv.TotalFleet,
                AdditionsAndDeletions = mmv.AdditionDeletionSum,
                MinFleet              = mmv.MinFleet,
                MaxFleet              = mmv.MaxFleet,
                Contribution          = mmv.Contribution,
            };

            var minMaxEntriesToBeInserted = maxMinValues.ToList();

            minMaxEntriesToBeInserted.BulkCopyToDatabase("AdditionPlanMinMaxValue", DataContext, "fao");


            var additionPlanEntryEntities = from wa in weeklyAdditions
                                            select new AdditionPlanEntry
            {
                Week                = (byte)wa.IsoWeek,
                Year                = (short)wa.Year,
                CarGroupId          = wa.GetCarGroupId(),
                LocationId          = wa.GetLocationId(),
                Additions           = wa.Amount,
                AdditionPlanId      = additionPlanId,
                ContributionPerUnit = (decimal)wa.Contribution,
            };


            var additionPlanEntriesToBeInserted = additionPlanEntryEntities.ToList();

            additionPlanEntriesToBeInserted.BulkCopyToDatabase("AdditionPlanEntry", DataContext, "fao");
        }