public IHttpActionResult GetRequestsByUserIDForConfirm(string userID) { List <Client_Request3> client_Requests = new List <Client_Request3>(); IssuingDAO issuingDAO = new IssuingDAO(); try { List <Request> requests = (from re in db.Requests where re.UserID == userID && re.IsIssued == true && re.IsConfirmed == false select re).ToList(); foreach (var request in requests) { Demand demand = db.Demands.Find(request.DemandPK); Conception conception = db.Conceptions.Find(demand.ConceptionPK); IssuingSession issuingSession = (from Iss in db.IssuingSessions where Iss.RequestPK == request.RequestPK select Iss).FirstOrDefault(); SystemUser systemUser = db.SystemUsers.Find(issuingSession.UserID); client_Requests.Add(new Client_Request3(request, demand, conception, issuingSession, systemUser)); } } catch (Exception e) { return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage())); } return(Content(HttpStatusCode.OK, client_Requests)); }
public IHttpActionResult PrepareRequest(int requestPK, string userID, [FromBody] Client_InputPrepareRequestAPI input) { if (new ValidationBeforeCommandDAO().IsValidUser(userID, "Staff")) { IssuingDAO issuingDAO = new IssuingDAO(); StoringDAO storingDAO = new StoringDAO(); BoxDAO boxDAO = new BoxDAO(); IssuingSession issuingSession = null; try { issuingDAO.UpdateRequest(requestPK, true); boxDAO.ChangeIsActiveBoxes(input.boxIDs, false); issuingSession = issuingDAO.CreateIssuingSession(userID, requestPK, input.boxIDs); storingDAO.CreateIssueEntry(input, issuingSession); } catch (Exception e) { if (issuingSession != null) { issuingDAO.UpdateRequest(requestPK, false); boxDAO.ChangeIsActiveBoxes(input.boxIDs, true); issuingDAO.DeleteIssuingSession(issuingSession.IssuingSessionPK); } return(Content(HttpStatusCode.Conflict, new Content_InnerException(e).InnerMessage())); } return(Content(HttpStatusCode.OK, "TẠO YÊU CẦU XUẤT THÀNH CÔNG!")); } else { return(Content(HttpStatusCode.Conflict, "BẠN KHÔNG CÓ QUYỀN ĐỂ THỰC HIỆN VIỆC NÀY!")); } }
public Client_IssuingSession(IssuingSession issuingSession, Demand demand, Request request, Conception conception) { IssuingSessionPK = issuingSession.IssuingSessionPK; ExecutedDate = issuingSession.ExecutedDate; DemandID = demand.DemandID; StartWeek = demand.StartWeek; EndWeek = demand.EndWeek; ReceiveDivision = demand.ReceiveDivision; ConceptionCode = conception.ConceptionCode; RequestID = request.RequestID; IsConfirmed = request.IsConfirmed; }
public void DeleteIssuingSession(int issuingSessionPK) { try { IssuingSession issuingSession = db.IssuingSessions.Find(issuingSessionPK); db.IssuingSessions.Remove(issuingSession); db.SaveChanges(); } catch (Exception e) { throw e; } }
public void CreateIssueEntry(Client_InputPrepareRequestAPI input, IssuingSession issuingSession) { try { Entry entry; Accessory accessory; foreach (var item_position_quantity in input.Item_position_quantities) { // lấy hàng cần xuất if (item_position_quantity.IsRestored) { RestoredItem restoredItem = db.RestoredItems.Find(item_position_quantity.ItemPK); accessory = db.Accessories.Find(restoredItem.AccessoryPK); } else { PassedItem passedItem = db.PassedItems.Find(item_position_quantity.ItemPK); ClassifiedItem classifiedItem = db.ClassifiedItems.Find(passedItem.ClassifiedItemPK); PackedItem packedItem = db.PackedItems.Find(classifiedItem.PackedItemPK); OrderedItem orderedItem = db.OrderedItems.Find(packedItem.OrderedItemPK); accessory = db.Accessories.Find(orderedItem.AccessoryPK); } // tạo entry xuất trong n - thùng chưa hàng foreach (var item in item_position_quantity.BoxAndQuantity) { StoredBox sBox = db.StoredBoxes.Find(item.StoredBoxPK); if (sBox == null) { throw new Exception("Data StoreBoxes Lỗi!"); } entry = new Entry(sBox, "Issuing", issuingSession.IssuingSessionPK, item_position_quantity.IsRestored, item.Quantity, item_position_quantity.ItemPK, accessory); db.Entries.Add(entry); } } db.SaveChanges(); } catch (Exception e) { throw e; } }
public void DeleteIssueEntries(int issuingSessionPK) { try { IssuingSession issuingSession = db.IssuingSessions.Find(issuingSessionPK); List <Entry> entries = (from e in db.Entries where e.KindRoleName == "Issuing" && e.SessionPK == issuingSessionPK select e).ToList(); foreach (var entry in entries) { db.Entries.Remove(entry); } db.SaveChanges(); } catch (Exception e) { throw e; } }
public IssuingSession CreateIssuingSession(string userID, int requestPK, List <string> boxIDs) { try { string deactivatedBoxes = ""; foreach (var boxID in boxIDs) { deactivatedBoxes += boxID + "~!~"; } IssuingSession issuingSession = new IssuingSession(userID, requestPK, deactivatedBoxes); db.IssuingSessions.Add(issuingSession); db.SaveChanges(); issuingSession = (from iS in db.IssuingSessions.OrderByDescending(unit => unit.IssuingSessionPK) select iS).FirstOrDefault(); return(issuingSession); } catch (Exception e) { throw e; } }
public Client_Request3(Request request, Demand demand, Conception conception, IssuingSession issuingSession, SystemUser systemUser) { RequestPK = request.RequestPK; RequestID = request.RequestID; DateCreated = request.DateCreated; ExpectedDate = request.ExpectedDate; Comment = request.Comment; DemandID = demand.DemandID; StartWeek = demand.StartWeek; EndWeek = demand.EndWeek; ReceiveDivision = demand.ReceiveDivision; ConceptionCode = conception.ConceptionCode; UserID = systemUser.UserID; Username = systemUser.Name; ExecutedDate = issuingSession.ExecutedDate; }