public IHttpActionResult DiscardInventory(string boxID, int itemPK, double discardedQuantity, bool isRestored, string userID, string comment) { if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff")) { BoxDAO boxDAO = new BoxDAO(); StoringDAO storingDAO = new StoringDAO(); DiscardingSession discardingSession = null; try { Box box = boxDAO.GetBoxByBoxID(boxID); StoredBox sBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK); if (sBox != null) { List <Entry> entries = (from e in db.Entries where e.StoredBoxPK == sBox.StoredBoxPK && e.ItemPK == itemPK && e.IsRestored == isRestored select e).ToList(); discardingSession = storingDAO.CreateDiscardingSession(comment, false, userID); if (discardedQuantity > storingDAO.EntriesQuantity(entries)) { storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession); } if (discardedQuantity < storingDAO.EntriesQuantity(entries)) { storingDAO.CreateDiscardEntry(sBox, itemPK, discardedQuantity, isRestored, discardingSession); } else { return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!")); } } else { if (discardingSession != null) { storingDAO.DeleteDiscardingSession(discardingSession.DiscardingSessionPK); } return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ!")); } } catch (Exception e) { return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage())); } return(Content(HttpStatusCode.OK, "THAY ĐỔI KHO THÀNH CÔNG!")); } else { return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!")); } }