// public void AddDisbursement(int requisitionId, List <int> requisitionNo) { List <int> disbursementIDList = new List <int>(); Disbursement d = new Disbursement(); List <int> requestedByList = new List <int>(); //EmpID List <string> departmentCodeList = new List <string>(); foreach (int i in requisitionNo) { requestedByList.Add((int)(EFBroker_Requisition.GetRequisitionByID(i).RequestedBy)); } //foreach requestedByList get depcode foreach (int i in requestedByList) { string departmentCode = EFBroker_DeptEmployee.GetDepartByEmpID(i).DeptCode.ToString(); if (departmentCodeList.Count() != 0) { bool add = true; foreach (string s in departmentCodeList) { if (s == departmentCode) { add = false; } } if (add) { departmentCodeList.Add(departmentCode); } } else { departmentCodeList.Add(departmentCode); } } //foreach depcode add disbursement + disbDetail foreach (string i in departmentCodeList) { //add Disbursement d.RetrievalID = requisitionId; d.DeptCode = i; d.Status = "Pending"; int disbursementId = EFBroker_Disbursement.AddNewDisbursment(d); disbursementIDList.Add(disbursementId);//auto increasement disbursementIDList after SaveChanges } foreach (int i in disbursementIDList) { string departmentCode = EFBroker_Disbursement.GetDisbursmentbyDisbID(i).DeptCode; foreach (int no in requisitionNo) { //update requisition table Requisition r = new Requisition(); r = EFBroker_Requisition.GetRequisitionByID(no); string dep = EFBroker_DeptEmployee.GetDepartByEmpID(r.RequestedBy ?? 0).DeptCode;//if null, ==0 if (dep == departmentCode) { r.Status = "InProgress";///////////////////////////////////////////// r.DisbursementID = i; EFBroker_Requisition.UpdateRequisition(r); } } AddDisbursemen_Item(i); } }