public ComponentStocks ConfirmOrder(ComponentUpdate componentUpdate) { ComponentHelper componentHelper = new ComponentHelper(); using (var ctx = new CoffeShopContext()) { List <Component> componentList = ctx.Components.ToList(); var componentStocks = componentHelper.CalculateNewStocks(componentUpdate, componentList); for (int i = 0; i < componentList.Count; i++) { if (componentList[i].ComponentName == "Milk") { componentList[i].Stock = componentStocks.MilkInStock; } else if (componentList[i].ComponentName == "Coffe") { componentList[i].Stock = componentStocks.CoffeInStock; } else if (componentList[i].ComponentName == "Water") { componentList[i].Stock = componentStocks.WaterInStock; } } ctx.SaveChanges(); return(componentStocks); } }