public void DeleteMovingSession(int movingSessionPK)
 {
     try
     {
         MovingSession movingSession = db.MovingSessions.Find(movingSessionPK);
         db.MovingSessions.Remove(movingSession);
         db.SaveChanges();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
 public MovingSession CreateMovingSession(StoredBox storedBox, Shelf shelf, string userID)
 {
     try
     {
         MovingSession movingSession = new MovingSession(storedBox, shelf, userID);
         db.MovingSessions.Add(movingSession);
         db.SaveChanges();
         movingSession = (from Mss in db.MovingSessions.OrderByDescending(unit => unit.MovingSessionPK)
                          select Mss).FirstOrDefault();
         return(movingSession);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #3
0
 public IHttpActionResult MoveStoredBox(string boxID, string shelfID, string userID)
 {
     if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff"))
     {
         BoxDAO        boxDAO        = new BoxDAO();
         StoringDAO    storingDAO    = new StoringDAO();
         MovingSession movingSession = null;
         try
         {
             Box       box       = boxDAO.GetBoxByBoxID(boxID);
             StoredBox storedBox = boxDAO.GetStoredBoxbyBoxPK(box.BoxPK);
             if (storedBox != null)
             {
                 Shelf shelf = boxDAO.GetShelfByShelfID(shelfID);
                 if (storedBox.ShelfPK != shelf.ShelfPK)
                 {
                     movingSession = storingDAO.CreateMovingSession(storedBox, shelf, userID);
                     storingDAO.UpdateStoredBoxShelfPK(storedBox.StoredBoxPK, shelf.ShelfPK);
                 }
                 else
                 {
                     return(Content(HttpStatusCode.Conflict, "KỆ KHÔNG HỢP LỆ!"));
                 }
             }
             else
             {
                 return(Content(HttpStatusCode.Conflict, "THÙNG KHÔNG HỢP LỆ!"));
             }
         }
         catch (Exception e)
         {
             if (movingSession != null)
             {
                 storingDAO.DeleteMovingSession(movingSession.MovingSessionPK);
             }
             return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage()));
         }
         return(Content(HttpStatusCode.OK, "CHUYỂN 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!"));
     }
 }