Esempio n. 1
0
        public IHttpActionResult StoreBoxBusiness(string boxID, string shelfID, string userID)
        {
            if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
            {
                BoxDAO         boxDAO         = new BoxDAO();
                StoringDAO     storingItemDAO = new StoringDAO();
                StoredBox      storedBox      = null;
                StoringSession storingSession = null;
                try
                {
                    // khởi tạo
                    Box   box   = boxDAO.GetBoxByBoxID(boxID);
                    Shelf shelf = (from s in db.Shelves
                                   where s.ShelfID == shelfID && s.ShelfID != "InvisibleShelf"
                                   select s).FirstOrDefault();
                    if (boxDAO.GetUnstoredBoxbyBoxPK(box.BoxPK).IsIdentified&& !boxDAO.IsStored(box.BoxPK))
                    {
                        // chạy lệnh store box
                        storedBox      = storingItemDAO.CreateStoredBox(box.BoxPK, shelf.ShelfPK);
                        storingSession = storingItemDAO.CreateStoringSession(box.BoxPK, userID);
                        storingItemDAO.CreateEntriesUpdatePassedItem(box, storedBox, storingSession);
                    }
                    else
                    {
                        return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ"));
                    }
                }
                catch (Exception e)
                {
                    if (storedBox != null)
                    {
                        storingItemDAO.DeleteStoredBox(storedBox.StoredBoxPK);
                    }
                    if (storingSession != null)
                    {
                        storingItemDAO.DeleteStoringSession(storingSession.StoringSessionPK);
                    }
                    return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
                }


                return(Content(HttpStatusCode.OK, "STORE THÙNG THÀNH CÔNG"));
            }
            else
            {
                return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY"));
            }
        }