public void SaveCollectionTimeAndDateToDisbursement(int requisitionId, string collectionPoint, DateTime date, string time) { EFBroker_Disbursement.UpdateRetrievalStatus(requisitionId, "Closed"); List <Disbursement> disbursementList = EFBroker_Disbursement.GetDisbursmentListbyRetrievalID(requisitionId); Random r = new Random(); foreach (Disbursement d in disbursementList) { string depCode = d.Department.DeptCode; if (EFBroker_DeptEmployee.GetCollectionPointbyDeptCode(depCode).CollectionPoint1 == collectionPoint)////////////////The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."} { d.CollectionDate = date; d.CollectionTime = time; int value = r.Next(1000, 9999); d.AccessCode = value.ToString(); d.Status = "Ready"; EFBroker_Disbursement.UpdateDisbursement(d); //Thread,asynctask for email Thread emailThread = new Thread(() => SendEmailToDepartmentRepresentative(depCode, d, collectionPoint)); emailThread.Start(); // } } }
//discard invalid disbursement and set requisitioin status to PRORITY if all qty zero public bool CheckInvalidDisbursement(int rId) { List <Disbursement> disbList = EFBroker_Disbursement.GetDisbursmentListbyRetrievalID(rId); Dictionary <Disbursement, bool> chkDisbStatus = new Dictionary <Disbursement, bool>(); bool valid = false; foreach (Disbursement d in disbList) { foreach (Disbursement_Item di in d.Disbursement_Item) { if (di.ActualQty != 0) { valid = true; } } chkDisbStatus.Add(d, valid); } if (!valid) { List <Requisition> reqList = new List <Requisition>(); foreach (Disbursement d in disbList) { Requisition r = EFBroker_Requisition.GetRequisitionByDisbID(d.DisbursementID); r.Status = "Priority"; r.DisbursementID = null; EFBroker_Requisition.UpdateRequisition(r); d.Status = "Invalid"; EFBroker_Disbursement.UpdateDisbursement(d); } } valid = false; foreach (KeyValuePair <Disbursement, bool> kvp in chkDisbStatus) { //if 1 of the disbursement is true => valid is true if (kvp.Value) { valid = true; } } if (!valid) // valid = false; { EFBroker_Disbursement.UpdateRetrievalStatus(rId, "Invalid"); } return(valid); }