public ResponseMessage CreateDispatch(TWCCDispatchPayload payload) { try { string dispatchNo = string.Empty; string structCode = string.Empty; int dispReuseCount = 0; int projectId = 1; List <dispatchedStrucCount> result = new List <dispatchedStrucCount>(); string count = string.Format("select count(*) as cnt from dispatch_requirement dr inner join disp_req_structure drs on dr.id = drs.dispreq_id inner join project_structure ps on drs.proj_struct_id = ps.id where ps.structure_id = {0} and dr.sitereq_id = {1}", payload.StructureId, payload.siteRequirementId); result = _context.Set <dispatchedStrucCount>().FromSqlRaw(count).ToList(); int dispatchedQuantity = result.FirstOrDefault().cnt; int excedCout = dispatchedQuantity + payload.Quantity; int totalcount = _context.SiteReqStructure.Single(s => s.SiteReqId == payload.siteRequirementId && s.StructId == payload.StructureId).Quantity ?? 0; if (totalcount < excedCout) { throw new ValueNotFoundException("Dispatch quantity should match the required quantity."); } ServiceType servType = _context.ServiceType.Where(x => x.Id == payload.ServiceTypeId).FirstOrDefault(); if (servType.Name == commonEnum.ServiceType.Fabrication.ToString()) { dispReuseCount = _context.DispatchRequirement.Include(m => m.Servicetype).Where(x => x.DispatchNo.Contains("DC")).Count() + 1; } else if (servType.Name == commonEnum.ServiceType.OutSourcing.ToString()) { dispReuseCount = _context.DispatchRequirement.Include(m => m.Servicetype).Where(x => x.DispatchNo.Contains("DC")).Count() + 1; } else if (servType.Name == commonEnum.ServiceType.Reuse.ToString()) { dispReuseCount = _context.DispatchRequirement.Include(m => m.Servicetype).Where(x => x.DispatchNo.Contains("DA")).Count() + 1; } SiteRequirement siteReqr = _context.SiteRequirement.Include(c => c.SiteReqStructure).Where(x => x.Id == payload.siteRequirementId).FirstOrDefault(); // for structure id override in multiple component if (servType.Name == commonEnum.ServiceType.Fabrication.ToString() || servType.Name == commonEnum.ServiceType.OutSourcing.ToString()) { // int structCount = _context.ProjectStructure.Count () + 1; // structCode = constantVal.StructureIdPrefix + structCount.ToString ().PadLeft (6, '0'); dispatchNo = constantVal.DispVendorPrefix + dispReuseCount.ToString().PadLeft(6, '0'); } if (servType.Name == commonEnum.ServiceType.Reuse.ToString()) { dispatchNo = constantVal.DispReusePrefix + dispReuseCount.ToString().PadLeft(6, '0'); } ResponseMessage responseMessage = new ResponseMessage(); using (var transaction = _context.Database.BeginTransaction()) { try { DispatchRequirement dispReq = new DispatchRequirement(); dispReq.CreatedAt = DateTime.Now; dispReq.CreatedBy = payload.CreatedBy; //TODO dispReq.DispatchNo = dispatchNo; dispReq.RoleId = 1; // TODO dispReq.ServicetypeId = payload.ServiceTypeId; dispReq.SitereqId = payload.siteRequirementId; dispReq.SiteReqStructid = _context.SiteReqStructure.Where(x => x.SiteReqId == payload.siteRequirementId && x.StructId == payload.StructureId).FirstOrDefault().Id; dispReq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString(); dispReq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString(); dispReq.ToProjectid = payload.ToProjectId; dispReq.Quantity = payload.Quantity; _context.DispatchRequirement.Add(dispReq); _context.SaveChanges(); int structCountDb = _context.ProjectStructure.Count(); for (int iQty = 1; iQty <= payload.Quantity; iQty++) { if (servType.Name == commonEnum.ServiceType.Fabrication.ToString() || servType.Name == commonEnum.ServiceType.OutSourcing.ToString()) { int structCount = structCountDb + iQty; structCode = constantVal.StructureIdPrefix + structCount.ToString().PadLeft(6, '0'); } ProjectStructure projectStructure = new ProjectStructure(); if (servType.Name == commonEnum.ServiceType.Fabrication.ToString() || servType.Name == commonEnum.ServiceType.OutSourcing.ToString()) { SiteReqStructure siteRequirementStructure = _context.SiteReqStructure.Where(x => x.SiteReqId == payload.siteRequirementId && x.StructId == payload.StructureId).FirstOrDefault(); projectStructure.StructureId = payload.StructureId; projectStructure.StructCode = structCode; projectStructure.ProjectId = payload.ToProjectId; projectStructure.DrawingNo = ""; projectStructure.ComponentsCount = 0; projectStructure.StructureAttributesVal = siteRequirementStructure != null ? siteRequirementStructure.StructureAttributesVal : ""; projectStructure.EstimatedWeight = 0; projectStructure.StructureStatus = Util.GetDescription(commonEnum.StructureStatus.NOTAVAILABLE).ToString(); projectStructure.CurrentStatus = Util.GetDescription(commonEnum.StructureInternalStatus.DISPATCHINPROGRESS).ToString(); projectStructure.IsDelete = false; projectStructure.CreatedBy = payload.CreatedBy; projectStructure.CreatedAt = DateTime.Now; _context.ProjectStructure.Add(projectStructure); _context.SaveChanges(); } else { ProjectStructure structDB = _context.ProjectStructure.Where(x => x.Id == payload.ProjectStructureId).FirstOrDefault(); structDB.CurrentStatus = Util.GetDescription(commonEnum.StructureInternalStatus.DISPATCHINPROGRESS).ToString(); structDB.StructureStatus = Util.GetDescription(commonEnum.StructureStatus.NOTAVAILABLE).ToString(); _context.SaveChanges(); } DispReqStructure dispStrcture = new DispReqStructure(); dispStrcture.ProjStructId = servType.Name == commonEnum.ServiceType.Fabrication.ToString() || servType.Name == commonEnum.ServiceType.OutSourcing.ToString() ? projectStructure.Id : payload.ProjectStructureId; dispStrcture.DispreqId = dispReq.Id; if (servType.Name == commonEnum.ServiceType.Reuse.ToString()) { dispStrcture.FromProjectId = payload.FromProjectId; dispStrcture.SurplusDate = payload.SurplusFromDate; } dispStrcture.DispStructStatus = Util.GetDescription(commonEnum.SiteDispStructureStatus.NEW).ToString(); _context.DispReqStructure.Add(dispStrcture); _context.SaveChanges(); if (servType.Name == commonEnum.ServiceType.Reuse.ToString()) { var componentList = _context.Component.Where(x => x.ProjStructId == payload.ProjectStructureId).ToList(); foreach (Component comp in componentList) { DispStructureComp dsc = new DispStructureComp(); dsc.DispStructureId = dispStrcture.Id; dsc.DispCompId = comp.Id; _context.DispStructureComp.Add(dsc); } _context.SaveChanges(); } } /***update site requirement Structure status ***/ CodeList dispQty = _context.Query <CodeList>().FromSqlRaw(string.Format("select count(*) as Id,'' as Name , 0 as ServiceTypeId from dispatch_requirement dr inner join disp_req_structure drs on dr.id = drs.dispreq_id inner join project_structure ps on drs.proj_struct_id = ps.id where ps.structure_id ={0} and dr.sitereq_id ={1} and drs.disp_struct_status <> '{2}'", payload.StructureId, payload.siteRequirementId, Util.GetDescription(commonEnum.SiteDispStructureStatus.REJECT).ToString())).FirstOrDefault(); var dispatchedStrucCount = dispQty.Id; SiteRequirement dbSiteReq = _context.SiteRequirement.Where(x => x.Id == payload.siteRequirementId).FirstOrDefault(); SiteReqStructure dbSiteReqStructure = _context.SiteReqStructure.Where(x => x.SiteReqId == payload.siteRequirementId && x.StructId == payload.StructureId).FirstOrDefault(); if (dbSiteReqStructure.Quantity > dispatchedStrucCount) { dbSiteReqStructure.Status = Util.GetDescription(commonEnum.SiteRequiremntStatus.PARTIALLYDISPATCHED).ToString(); } else { dbSiteReqStructure.Status = Util.GetDescription(commonEnum.SiteRequiremntStatus.DISPATCHED).ToString(); } _context.SaveChanges(); /***update site requirement status ***/ List <SiteReqStructure> lstReqStructure = _context.SiteReqStructure.Where(x => x.SiteReqId == payload.siteRequirementId).ToList(); if (lstReqStructure.Count() > 0 && lstReqStructure.Where(x => x.Status != Util.GetDescription(commonEnum.SiteRequiremntStatus.DISPATCHED).ToString()).Count() > 0) { dbSiteReq.Status = Util.GetDescription(commonEnum.SiteRequiremntStatus.PARTIALLYDISPATCHED).ToString(); dbSiteReq.StatusInternal = Util.GetDescription(commonEnum.SiteRequiremntStatus.PARTIALLYDISPATCHED).ToString(); } else { dbSiteReq.Status = Util.GetDescription(commonEnum.SiteRequiremntStatus.DISPATCHED).ToString(); dbSiteReq.StatusInternal = Util.GetDescription(commonEnum.SiteRequiremntStatus.DISPATCHED).ToString(); } _context.SaveChanges(); DisreqStatusHistory dispatchReqStatusHistory = new DisreqStatusHistory(); dispatchReqStatusHistory.DispatchNo = dispatchNo; dispatchReqStatusHistory.DispreqId = dispReq.Id; dispatchReqStatusHistory.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString(); dispatchReqStatusHistory.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString(); dispatchReqStatusHistory.Notes = ""; dispatchReqStatusHistory.RoleId = payload.RoleId; dispatchReqStatusHistory.CreatedBy = payload.CreatedBy; dispatchReqStatusHistory.CreatedAt = DateTime.Now; _context.DisreqStatusHistory.Add(dispatchReqStatusHistory); _context.SaveChanges(); transaction.Commit(); responseMessage = new ResponseMessage() { Message = "Saved Successfully" }; } catch (Exception ex) { transaction.Rollback(); responseMessage = new ResponseMessage() { Message = "Error was found. Exception : " + ex.Message }; throw ex; } } return(responseMessage); } catch (Exception ex) { throw ex; } }
public ResponseMessage SiteDispatchRejection(SiteDispatchApproval dispAppr) { ResponseMessage res = new ResponseMessage(); string status = ""; string internalStatus = ""; ServiceType servType = _context.ServiceType.Where(x => x.Id == dispAppr.serviceTypeId).FirstOrDefault(); Roles roleDB = _context.Roles.Where(x => x.Name == dispAppr.roleName).FirstOrDefault(); DispatchRequirement dispReq = _context.DispatchRequirement.Where(x => x.Id == dispAppr.dispReqId).FirstOrDefault(); if (roleDB == null) { throw new ValueNotFoundException(String.Format("Rolename doesnt exists. {0}", dispAppr.roleName)); } if (dispReq == null) { throw new ValueNotFoundException(String.Format("Dispatch Id doesnt exists")); } if (servType.Name == commonEnum.ServiceType.Reuse.ToString()) { if (dispAppr.roleName == commonEnum.Rolename.SITE.ToString() && dispAppr.roleHierarchy == 3 && dispReq.StatusInternal == Util.GetDescription(commonEnum.SiteDispatchSatus.FAAAPPROVED).ToString()) { status = Util.GetDescription(commonEnum.SiteDispatchSatus.REJECT).ToString(); internalStatus = Util.GetDescription(Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED)).ToString(); } else if (dispAppr.roleName == commonEnum.Rolename.SITE.ToString() && dispAppr.roleHierarchy == 4) { status = Util.GetDescription(commonEnum.SiteDispatchSatus.REJECT).ToString(); internalStatus = Util.GetDescription(Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED)).ToString(); } else { throw new ValueNotFoundException(String.Format("Not allowed to approve for this role:{0}", dispAppr.roleName)); } } else { if (dispAppr.roleName == commonEnum.Rolename.SITE.ToString() && dispAppr.roleHierarchy == 3 && dispReq.StatusInternal == Util.GetDescription(commonEnum.SiteDispatchSatus.PROCAPPROVED).ToString()) { status = Util.GetDescription(commonEnum.SiteDispatchSatus.REJECT).ToString(); internalStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.NEW).ToString(); } else { throw new ValueNotFoundException(String.Format("Not allowed to approve for this role:{0}", dispAppr.roleName)); } } dispReq.Status = status; dispReq.StatusInternal = internalStatus; dispReq.RoleId = 1; //TODO dispReq.UpdatedAt = DateTime.Now; dispReq.UpdatedBy = 1; //TODO DisreqStatusHistory dispStatusHist = new DisreqStatusHistory(); dispStatusHist.DispatchNo = dispReq.DispatchNo; dispStatusHist.DispreqId = dispReq.Id; dispStatusHist.RoleId = dispAppr.roleId; dispStatusHist.Status = status; dispStatusHist.StatusInternal = internalStatus; dispStatusHist.CreatedAt = DateTime.Now; dispStatusHist.CreatedBy = 1; //TODO res.Message = String.Format(" site dispatch {0} Rejected Successfully.", dispReq.DispatchNo); return(res); }
public ResponseMessage UpdateComponentHistory(DispComponentDto Component) { using (var transaction = _context.Database.BeginTransaction()) { try { ResponseMessage responseMessage = new ResponseMessage(); List <ComponentDetailsInput> result = new List <ComponentDetailsInput>(); int id = Component.DispStructureId; string strQuery = string.Format("select dsc.id DispstructCompId, dsc.disp_structure_id DispStructureId,c.id DispCompId from disp_structure_comp dsc inner join component c on dsc.disp_comp_id = c.id inner join disp_mod_stage_component dmsc on dmsc.dispstruct_comp_id =dsc.id inner join component_type ct on c.comp_type_id =ct.id where dsc.disp_structure_id ={0}", id); result = _context.Query <ComponentDetailsInput>().FromSqlRaw(strQuery).ToList(); List <DispStructureComp> dispStructureComp = _context.DispStructureComp.Where(w => w.DispStructureId == Component.DispStructureId).ToList(); result.ForEach(item => { Component compDetails = _context.Component.Single(w => w.Id == item.DispCompId); ComponentHistory AddItem = new ComponentHistory(); if (compDetails != null) { AddItem.Weight = compDetails.Weight; AddItem.Leng = compDetails.Leng; AddItem.Breath = compDetails.Breath; AddItem.Height = compDetails.Height; AddItem.Thickness = compDetails.Thickness; //AddItem.MakeType=compDetails.MakeType; AddItem.CreatedAt = DateTime.Now; AddItem.CreatedBy = 1; //To do AddItem.ProjStructId = compDetails.ProjStructId; AddItem.CompId = compDetails.CompId; AddItem.ProjStructId = compDetails.ProjStructId; AddItem.CompTypeId = compDetails.CompTypeId; } _context.ComponentHistory.Add(AddItem); _context.SaveChanges(); DispModStageComponent compModStageDetails = _context.DispModStageComponent.OrderByDescending(o => o.CreatedAt).FirstOrDefault(x => x.DispstructCompId == item.DispstructCompId); compDetails.Weight = compModStageDetails.Weight; compDetails.Leng = compModStageDetails.Leng; compDetails.Breath = compModStageDetails.Breath; compDetails.Height = compModStageDetails.Height; compDetails.Thickness = compModStageDetails.Thickness; compDetails.MakeType = compModStageDetails.MakeType; compDetails.ProjStructId = compDetails.ProjStructId; _context.Component.Update(compDetails); _context.SaveChanges(); }); DispReqStructure structid = _context.DispReqStructure.FirstOrDefault(w => w.ProjStructId == Component.ProjectStructureId && w.Id == Component.DispStructureId); if (Component.IsVendor) { if (structid != null) { { responseMessage = _dispatchReqSubConRepository.OSAssignVendor(Component.OSDispatchReqSubCont); } structid.DispStructStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString(); _context.DispReqStructure.Update(structid); _context.SaveChanges(); } } if (Component.IsSite) { DispReqStructure dispstructid = _context.DispReqStructure.SingleOrDefault(w => w.ProjStructId == Component.ProjectStructureId && w.Id == Component.DispStructureId); if (dispstructid != null) { dispstructid.DispStructStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); _context.DispReqStructure.Update(dispstructid); _context.SaveChanges(); } } DisreqStatusHistory disReqHis = new DisreqStatusHistory(); DispatchRequirement disreq = _context.DispatchRequirement .SingleOrDefault(w => w.Id == Component.DispatchRequirementId); var totalCount = _context.DispReqStructure.Where(x => x.DispreqId == Component.DispatchRequirementId).Count(); var appCount = _context.DispReqStructure.Where(x => x.DispreqId == Component.DispatchRequirementId && (x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString() || x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString())).Count(); // if(disreq!=null){ // throw new ValueNotFoundException ("DispatchRequirementId Not Available"); // } if (totalCount != appCount) { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCPARIALLYMODIFYAPRD).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCPARIALLYMODIFYAPRD).ToString(); disreq.UpdatedBy = 1; //To DO disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCPARIALLYMODIFYAPRD).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCPARIALLYMODIFYAPRD).ToString(); disreq.UpdatedAt = DateTime.Now; disReqHis.DispatchNo = disreq.DispatchNo; disReqHis.RoleId = disreq.RoleId; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } else { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString(); disreq.UpdatedBy = 1; //To DO disreq.UpdatedAt = DateTime.Now; disReqHis.DispatchNo = disreq.DispatchNo; disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.TWCCMODIFYAPRD).ToString(); disReqHis.RoleId = disreq.RoleId; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } _context.DispatchRequirement.Update(disreq); _context.DisreqStatusHistory.Add(disReqHis); _context.SaveChanges(); responseMessage.Message = "Component updated"; transaction.Commit(); return(responseMessage); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public ResponseMessage UpdatestructureModify(List <DispReqStructureDto> structure) { try { ResponseMessage responseMessage = new ResponseMessage(); structure.ForEach(item => { DispReqStructure structid = _context.DispReqStructure.Single(w => w.ProjStructId == item.ProjStructId && w.DispreqId == item.DispreqId); DispatchRequirement disreq = _context.DispatchRequirement .Single(w => w.Id == item.DispatchRequirementId); if (structid != null && disreq != null) { if (disreq.Status != "NEW") { responseMessage.Message = "Invalid Status"; } else { if (item.IsModification) { structid.IsModification = item.IsModification; structid.DispStructStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString(); } else { structid.IsModification = item.IsModification; structid.DispStructStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); } responseMessage.Message = "Structure Modification status updated"; } } _context.DispReqStructure.Update(structid); _context.SaveChanges(); }); structure.ForEach(item => { DisreqStatusHistory disReqHis = new DisreqStatusHistory(); DispatchRequirement disreq = _context.DispatchRequirement .Single(w => w.Id == item.DispatchRequirementId); var totalCount = _context.DispReqStructure.Where(x => x.DispreqId == item.DispatchRequirementId).Count(); var appCount = _context.DispReqStructure.Where(x => x.DispreqId == item.DispatchRequirementId && x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString()).Count(); var delivCount = _context.DispReqStructure.Where(x => x.DispreqId == item.DispatchRequirementId && x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString()).Count(); if (totalCount != appCount) { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disreq.UpdatedBy = 1; //To DO disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disreq.UpdatedAt = DateTime.Now; disReqHis.DispatchNo = disreq.DispatchNo; disReqHis.RoleId = disreq.RoleId; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } else { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCAPPROVED).ToString(); disreq.UpdatedBy = 1; //To DO disreq.UpdatedAt = DateTime.Now; disReqHis.DispatchNo = disreq.DispatchNo; disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYAPPROVED).ToString(); disReqHis.RoleId = disreq.RoleId; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } if (totalCount == delivCount) { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); disreq.UpdatedBy = 1; //To DO disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.READYTODELIVER).ToString(); disreq.UpdatedAt = DateTime.Now; disReqHis.DispatchNo = disreq.DispatchNo; disReqHis.RoleId = disreq.RoleId; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } _context.DispatchRequirement.Update(disreq); _context.DisreqStatusHistory.Add(disReqHis); _context.SaveChanges(); }); return(responseMessage); } catch (Exception ex) { throw ex; } }
public ResponseMessage UpdateDispatchComponent(List <DispModStageComponentDto> Component) { try { ResponseMessage responseMessage = new ResponseMessage(); Component.ForEach(item => { DisreqStatusHistory disReqHis = new DisreqStatusHistory(); DispModStageComponent AddItem = new DispModStageComponent(); if (item != null) { AddItem.DispstructCompId = item.DispstructCompId; AddItem.Weight = item.Weight; AddItem.Leng = item.Leng; AddItem.Breath = item.Breath; AddItem.Height = item.Height; AddItem.Thickness = item.Thickness; AddItem.MakeType = item.MakeType; AddItem.Addplate = item.Addplate; AddItem.CreatedAt = DateTime.Now; } DispReqStructure structid = _context.DispReqStructure.Single(w => w.ProjStructId == item.ProjectStructureId && w.Id == item.DispStructureId); if (structid != null) { structid.DispStructStatus = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disReqHis.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disReqHis.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disReqHis.DispatchNo = item.DCNumber; disReqHis.CreatedBy = 1; //To DO disReqHis.CreatedAt = DateTime.Now; } _context.DispReqStructure.Update(structid); _context.DispModStageComponent.Add(AddItem); _context.DisreqStatusHistory.Add(disReqHis); _context.SaveChanges(); DispatchRequirement disreq = _context.DispatchRequirement .Single(w => w.Id == item.DispatchRequirementId); var totalCount = _context.DispReqStructure.Where(x => x.DispreqId == item.DispatchRequirementId).Count(); var appCount = _context.DispReqStructure.Where(x => x.DispreqId == item.DispatchRequirementId && x.DispStructStatus == Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString()).Count(); DisreqStatusHistory disReqHis1 = new DisreqStatusHistory(); if (totalCount != appCount) { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYMODIFIED).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYMODIFIED).ToString(); disreq.UpdatedBy = 1; //To DO disreq.UpdatedAt = DateTime.Now; disReqHis1.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYMODIFIED).ToString(); disReqHis1.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCPARTIALLYMODIFIED).ToString(); disReqHis1.DispatchNo = disreq.DispatchNo; disReqHis1.RoleId = disreq.RoleId; disReqHis1.CreatedBy = 1; //To DO disReqHis1.CreatedAt = DateTime.Now; } else { disreq.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disreq.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disreq.UpdatedBy = 1; //To DO disreq.UpdatedAt = DateTime.Now; disReqHis1.DispatchNo = item.DCNumber; disReqHis1.Status = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disReqHis1.StatusInternal = Util.GetDescription(commonEnum.SiteDispatchSatus.CMPCMODIFIED).ToString(); disReqHis1.RoleId = disreq.RoleId; disReqHis1.CreatedBy = 1; //To DO disReqHis1.CreatedAt = DateTime.Now; disReqHis1.DispreqId = item.DispatchRequirementId; } _context.DispatchRequirement.Update(disreq); _context.DisreqStatusHistory.Add(disReqHis1); _context.SaveChanges(); responseMessage.Message = "Component updated"; }); return(responseMessage); } catch (Exception ex) { throw ex; } }