public static string CloseRequest(CloseRequestObjForStg_4 data) { using (var context = new SalesReturndbEntities()) { string AssignTo = string.Empty; string RetMsg = string.Empty; var RequestDetail = context.tblRequestDtls.Where(x => x.RequestHeaderId == data.Request_Id).ToList(); var approvalHeader = context.TblApproverHeaders.Where(x => x.Request_Id == data.Request_Id).FirstOrDefault(); var ReqHdr = context.TblRequestHeaders.Where(x => x.RequestHeaderId == data.Request_Id && x.IsActive == true).FirstOrDefault(); var UserDetail = context.SP_LFGDetails(approvalHeader.CreatedBy).FirstOrDefault(); var DlrDtl = context.sp_GetDealerDtlBy_DealerRepositoryId(data.Request.DealerId).FirstOrDefault(); if (data.FutureStatus_Id == 10027 || data.CurrentStatus_Id == 10028 || data.CurrentStatus_Id == 10029) { var EmpMaster = context.TblEmployeeMasters.Where(x => x.DepotName == DlrDtl.Depot && x.IsActive == true).FirstOrDefault(); AssignTo = data.FutureStatus_Id == 10027 ? EmpMaster.Depotcode : ""; if (data.Request.IsCommercialSettlement == true) { var EpCheck = context.sp_CheckEPNumber(data.Request.EPNo).FirstOrDefault(); if (EpCheck == null) { return("Error: EP Number does not exists"); } } ReqHdr.IsCommercialSettlement = data.Request.IsCommercialSettlement; ReqHdr.MaterialWillGoToDealer = data.Request.IsCommercialSettlement == true ? false : true; ReqHdr.ReasonForCommercialSettlement = data.Request.IsCommercialSettlement == true ? data.Request.ReasonForCommercialSettlement : ""; ReqHdr.DetailsForMaterialGoToDealer = data.Request.IsCommercialSettlement == false ? data.Request.DetailsForMaterialGoToDealer : ""; ReqHdr.EPNo = data.Request.IsCommercialSettlement == true ? data.Request.EPNo : ""; ReqHdr.ModifiedBy = data.EmployeeCode; ReqHdr.ModifiedDate = DateTime.Now; context.Entry(ReqHdr).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); RetMsg = data.FutureStatus_Id == 10027 ? "Request has been forwarded to Depot!" : "Request has been closed successfully!"; } else if (data.CurrentStatus_Id == 10030) { ReqHdr.DocketNumber = data.Request.DocketNumber; ReqHdr.DocketDate = data.Request.DocketDate; context.Entry(ReqHdr).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); RetMsg = "Request has been closed successfully!"; } else { RetMsg = "Request has been closed successfully!"; } ApproverDAL.UpdateRequestStatus(false, Convert.ToInt32(data.Request_Id), data.EmployeeCode, AssignTo, data.Active_Role, data.Requested_Role, data.CurrentStatus_Id, data.FutureStatus_Id, data.Remarks); return("Success : " + ReqHdr.RequestTypeOption + data.Request_Id + " " + RetMsg); } }