public JsonResult UpdateWarehouseID(string list) { var json = new JavaScriptSerializer().Deserialize <List <Inventory> >(list); var listInventory = new InventoryDao().ListInventoryByOrderId(json[0].OrderID); var dao = new InventoryDao(); Inventory inventory = new Inventory(); if (listInventory.Count() > 0) { foreach (var item in json) { var rem = listInventory.Single(x => x.ProductID == item.ProductID); item.ID = rem.ID; listInventory.Remove(rem); listInventory.Add(item); } foreach (var item in listInventory) { inventory.ID = item.ID; inventory.OrderID = item.OrderID; inventory.ProductID = item.ProductID; inventory.Quantity = item.Quantity; inventory.WarehouseID = item.WarehouseID; inventory.Date = DateTime.Now; dao.Update(inventory); } } else { foreach (var item in json) { listInventory.Add(item); } foreach (var item in listInventory) { dao.Insert(item); } } return(Json(new { status = true })); }
public JsonResult ImportDetail(string list) { var json = new JavaScriptSerializer().Deserialize <List <Inventory> >(list); var accDocDetailDao = new AccDocDetailDao(); AccDocDetail accDocDetail = new AccDocDetail(); var inventoryDao = new InventoryDao(); Inventory inventory = new Inventory(); if (json.Count() > 0) { accDocDetailDao.RemoveDetail(json[0].DocNo); inventoryDao.RemoveDetail(json[0].DocNo); foreach (var item in json) { //Insert detail vào bảng AccDocDetail accDocDetail.DocCode = item.DocCode; accDocDetail.DocNo = item.DocNo; accDocDetail.WarehouseID = item.WarehouseID; accDocDetail.ProductID = item.ProductID; accDocDetail.Quantity = item.Quantity; if (accDocDetailDao.CheckExist(accDocDetail.DocCode, accDocDetail.DocNo, accDocDetail.WarehouseID, accDocDetail.ProductID) == true) { accDocDetailDao.UpdateQuantity(accDocDetail.DocCode, accDocDetail.DocNo, accDocDetail.WarehouseID, accDocDetail.ProductID, (int)accDocDetail.Quantity); } else { accDocDetailDao.Insert(accDocDetail); } //Insert detail vào bảng Inventory if (inventoryDao.CheckExist(accDocDetail.DocCode, accDocDetail.DocNo, accDocDetail.WarehouseID, accDocDetail.ProductID) == true) { inventoryDao.UpdateQuantity(accDocDetail.DocCode, accDocDetail.DocNo, accDocDetail.WarehouseID, accDocDetail.ProductID, (int)item.Quantity); } else { inventoryDao.Insert(item); } } } return(Json(new { status = true })); }
public ActionResult Supply(Order order) { if (ModelState.IsValid) { //Đổi trạng thái của Order về 3: Supplied order.Status = new OrderDao().ChangeStatus(order.ID, 3); var detailList = new OrderDetailDao().ListDetailByOrderId(order.ID); var invent = new Inventory(); var dao = new InventoryDao(); //Insert vào bảng Inventory if (dao.ListInventoryByOrderId(order.ID).Count() == 0) { foreach (var item in detailList) { invent.OrderID = item.OrderID; invent.DocCode = "OR"; invent.Date = DateTime.Now; invent.ProductID = item.ProductID; invent.Quantity = item.Quantity; invent.Status = true; var id = dao.Insert(invent); invent.DocNo = dao.UpdateDocNo("OR", id, order.ID); } } if (order.Status == 3) { SetAlert("Supply this order successfully.", "success"); } else { ModelState.AddModelError("", "Supply this order failed."); } } var inventory = new InventoryDao().ListInventoryViewByOrderId(order.ID); ViewBag.Inventory = inventory; SetStatusViewBag(order.Status); return(View(order)); }