public int updateDisburse(string deptid, string empid1) { int empid = Convert.ToInt32(empid1); var ddptg = (from odr in ad.Requests where odr.RequestStatus == "Alloted" && odr.RequestByDepartmentID == deptid select odr).ToList(); foreach (var qin in ddptg) { var outstand = (from ot in ad.RequestDetails where ot.RequestID == qin.RequestID && ot.RequestedQty != ot.ReceivedQty select ot).ToList(); if (outstand.Count > 0) { Request reqout = new Request { RequestStatus = "NEW", RequestByDepartmentID = qin.RequestByDepartmentID, RequestByEmployeeID = empid }; ad.Requests.Add(reqout); try { ad.SaveChanges(); } catch (Exception tye) { Console.WriteLine(tye); } var genReqNo = (from grn1 in ad.Requests where grn1.RequestStatus == "NEW" && grn1.RequestByEmployeeID == empid && grn1.RequestByDepartmentID == qin.RequestByDepartmentID select grn1).ToList(); int reqnoutstand = genReqNo[0].RequestID; EmpNewRequest outstandnewreq = new EmpNewRequest(); foreach (var outstandvar in outstand) { int qtyoutstand = (int)(outstandvar.RequestedQty - outstandvar.ReceivedQty); outstandnewreq.AddItem(reqnoutstand, outstandvar.RequestedItem, qtyoutstand); } outstandnewreq.AddOutStandingReqNo(reqnoutstand); } var all12 = from a12 in ad.Requests where a12.RequestID == qin.RequestID select a12; Request req = all12.First(); req.RequestStatus = "Disbursed"; req.ReceivedDate = System.DateTime.Now.Date; try { ad.SaveChanges(); } catch (Exception tye) { Console.WriteLine(tye); return(0); } } return(1); }