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); } }