Exemple #1
0
 public IHttpActionResult AdjustInventory(string boxID, int itemPK, double adjustedQuantity, bool isRestored, string userID, string comment)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO           boxDAO           = new BoxDAO();
         StoringDAO       storingDAO       = new StoringDAO();
         AdjustingSession adjustingSession = 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();
                 adjustingSession = storingDAO.CreateAdjustingSession(comment, false, userID);
                 if (adjustedQuantity > storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateAdjustEntry(sBox, itemPK, adjustedQuantity, isRestored, false, adjustingSession);
                 }
                 if (adjustedQuantity < storingDAO.EntriesQuantity(entries))
                 {
                     storingDAO.CreateAdjustEntry(sBox, itemPK, adjustedQuantity, isRestored, true, adjustingSession);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "SỐ LƯỢNG KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 if (adjustingSession != null)
                 {
                     storingDAO.DeleteAdjustingSession(adjustingSession.AdjustingSessionPK);
                 }
                 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!"));
     }
 }