private static void AddorUpdateAmc(int itemId, int storeId,int amcRange, DateTime endDate, AmcReportRepository amcrepo, AMCViewModel viewModel, AmcReport allItemIds, DateTime startDate)
 {
     if (allItemIds != null)
     {
         allItemIds.IssueInAmcRange = Builder.CalculateTotalConsumptionWithoutDOS(itemId, storeId, startDate, endDate);
         allItemIds.IssueWithDOS = Builder.CalculateTotalConsumptionAMC(itemId, storeId, startDate, endDate);
         allItemIds.AmcWithDOS = Builder.CalculateTotalConsumptionAMC(itemId, storeId, startDate, endDate) / Convert.ToDouble(viewModel.AmcRange);
         allItemIds.AmcWithOutDOS = Builder.CalculateTotalConsumptionWithoutDOS(itemId, storeId, startDate, endDate) / Convert.ToDouble(viewModel.AmcRange);
         allItemIds.DaysOutOfStock = Builder.CalculateStockoutDays(itemId, storeId, startDate, DateTime.Now);
         allItemIds.AmcRange = amcRange;
         allItemIds.LastIndexedTime = DateTime.Now;
         amcrepo.Update(allItemIds);
     }
     else
     {
         var amcreport = new AmcReport
         {
             ItemID = itemId,
             StoreID = storeId,
             AmcRange = amcRange,
             IssueWithDOS = Builder.CalculateTotalConsumptionAMC(itemId, storeId, startDate, endDate),
             IssueInAmcRange = Builder.CalculateTotalConsumptionWithoutDOS(itemId, storeId, startDate, endDate),
             DaysOutOfStock = Builder.CalculateStockoutDays(itemId, storeId, startDate, DateTime.Now),
             AmcWithDOS = Builder.CalculateTotalConsumptionAMC(itemId, storeId, startDate, endDate) / Convert.ToDouble(viewModel.AmcRange),
             AmcWithOutDOS = Builder.CalculateTotalConsumptionWithoutDOS(itemId, storeId, startDate, endDate) / Convert.ToDouble(viewModel.AmcRange),
             LastIndexedTime = DateTime.Now
         };
         amcrepo.Add(amcreport);
     }
 }
        private static void AddAMCForUnit(int itemId, string itemFullName, int storeId,int unitid, int amcRange, DateTime endDate, DateTime startDate)
        {
            var amcrepo = new AmcReportRepository();
            var DOS = Builder.CalculateStockoutDays(itemId, storeId, startDate, DateTime.Now);
            var totalCAMC = Builder.CalculateTotalConsumptionAMC(itemId, storeId, startDate, endDate, amcRange, DOS);
            var totalCWDOS = Builder.CalculateTotalConsumptionWithoutDOS(itemId, storeId, startDate,endDate);

            var amcreport = new AmcReport
                            {
                                ItemID = itemId,
                                StoreID = storeId,
                                AmcRange = amcRange,
                                IssueWithDOS = totalCAMC,
                                IssueInAmcRange = totalCWDOS,
                                DaysOutOfStock = DOS,
                                AmcWithDOS = totalCAMC / amcRange,
                                AmcWithOutDOS = totalCWDOS / amcRange,
                                LastIndexedTime = DateTime.Now,
                                UnitID = unitid
                            };

            amcreport.FullItemName = itemFullName;
            amcrepo.Add(amcreport);
        }