Esempio n. 1
0
 public IHttpActionResult UpdateDisbursementDetailByItem(CustomRequisition[] requisitions)
 {
     for (int i = 0; i < requisitions.Length; i++)
     {
         CustomRequisition requisition = requisitions[i];
         CustomItem        item        = requisition.CustomItems[0];
         RequisitionDetail detail      = db.RequisitionDetails.SingleOrDefault(r => r.RequisitionID == requisition.RequisitionID &&
                                                                               r.ItemID == item.ItemID);
         detail.QuantityReceived = item.QuantityReceived;
         db.SaveChanges();
     }
     return(Ok());
 }
Esempio n. 2
0
        public IHttpActionResult GetRequisitionDetail(int id)
        {
            string employeeName = db.Requisitions.SingleOrDefault(r => r.RequisitionID == id).Employee.ToString();

            CustomItem[] items = db.RequisitionDetails.Where(r => r.RequisitionID == id)
                                 .Select(r => new CustomItem
            {
                ItemID      = r.ItemID,
                Description = r.Item.Description,
                Quantity    = r.Quantity
            }).ToArray();
            CustomRequisition customRequisition = new CustomRequisition
            {
                RequisitionID = id,
                EmployeeName  = employeeName,
                CustomItems   = items
            };

            return(Ok(customRequisition));
        }
Esempio n. 3
0
        public IHttpActionResult UpdateRequisition(CustomRequisition customRequisition)
        {
            int requisitionId   = customRequisition.RequisitionID;
            int retrievalListId = FindCurrentRetrievalList().RetrievalListID;

            CustomItem[] items = customRequisition.CustomItems;
            for (int i = 0; i < items.Length; i++)
            {
                CustomItem        item   = items[i];
                RequisitionDetail detail = db.RequisitionDetails.SingleOrDefault(
                    r => r.RequisitionID == requisitionId && r.ItemID == item.ItemID);
                detail.QuantityReceived = item.QuantityReceived;
                if (item.QuantityReceived < detail.Quantity)
                {
                    int departmentId = detail.Requisition.Employee.DepartmentID;
                    RetrievalListDetail retrievalListDetail = db.RetrievalListDetails.SingleOrDefault(
                        r => r.RetrievalListID == retrievalListId &&
                        r.DepartmentID == departmentId && r.ItemID == item.ItemID);
                    if (retrievalListDetail == null)
                    {
                        retrievalListDetail = new RetrievalListDetail
                        {
                            RetrievalListID = retrievalListId,
                            DepartmentID    = departmentId,
                            ItemID          = item.ItemID,
                            Quantity        = detail.Quantity - item.QuantityReceived
                        };
                        db.RetrievalListDetails.Add(retrievalListDetail);
                    }
                    else
                    {
                        retrievalListDetail.Quantity += (detail.Quantity - item.QuantityReceived);
                    }
                    RequisitionRetrieval requisitionRetrieval = db.RequisitionRetrievals.SingleOrDefault(r => r.RequisitionID == requisitionId);
                    requisitionRetrieval.RetrievalListID = retrievalListId;
                }
            }
            db.SaveChanges();
            return(Ok());
        }