public ActionResult Save(WarehouseBL ware, List <Shelves> shel, List <Depot> depot) { WarehouseDBEntities wdb = new WarehouseDBEntities(); Shelves s = new Shelves(); WarehouseBusinessLayer warehouseBL = new WarehouseBusinessLayer(); ware.managerId = Convert.ToInt32(Session["UserID"]); warehouseBL.UpdateWareHouse(ware); int shelfCount = shel.Count; int zoneA = s.ZoneAshelf(shelfCount); int zoneB = s.ZoneBshelf(shelfCount); int zoneC = s.ZoneCshelf(shelfCount, zoneA, zoneB); shel = s.ShelvesWithDistance(shel, depot); shel = s.SortShelves(shel); shel = s.assignZones(shel, zoneA, zoneB, zoneC); foreach (Shelves shelve in shel) { shelve.warehouse_id = warehouseBL.getWarehouseId(Convert.ToInt32(Session["UserID"])); int myid = warehouseBL.getWarehouseId(Convert.ToInt32(Session["UserID"])); bool isExist = wdb.Shelves.Any(u => u.shelfName == myid.ToString() + shelve.shelveID); if (isExist) { shelve.shelveID = shelve.warehouse_id + shelve.shelveID; warehouseBL.UpdateShelf(shelve); } else { shelve.shelveID = shelve.warehouse_id + shelve.shelveID; int warehouseID = warehouseBL.getWarehouseId(Convert.ToInt32(Session["UserID"])); JavaScriptSerializer jss = new JavaScriptSerializer(); Warehouse warehouse = wdb.Warehouses.Find(warehouseID); List <ShelfItems> shelfItems = new List <ShelfItems>(); int z = 1; for (int i = 1; i <= warehouse.shelfSlots; i++) { ShelfItems si = new ShelfItems(); si.slot_id = i; si.item_id = -1; si.item_name = ""; si.expiry_date = ""; si.status = 0; if (i - warehouse.sections <= 0) { si.section_id = i; } else if (i - warehouse.sections > 0 && i - warehouse.sections * z <= warehouse.sections) { si.section_id = i - (int)warehouse.sections * z; } else { z += 1; si.section_id = i - ((int)warehouse.sections * z); } shelfItems.Add(si); } string output = JsonConvert.SerializeObject(shelfItems); shelve.slotsRemaining = warehouse.shelfSlots; shelve.shelfItems = output; warehouseBL.AddShelf(shelve); } } return(RedirectToAction("LoggedIn", "Account")); }