public async Task SubmitAdditionalInfoToLicense(Guid appId, string text) { var application = DataService.GetEntity <PrlApplication>(x => x.Id == appId).FirstOrDefault(); if (application == null) { throw new Exception(); } var organization = DataService.GetEntity <OrganizationExt>(x => x.Id == application.OrgUnitId).FirstOrDefault(); if (organization == null) { throw new Exception(); } var orgInfo = DataService.GetEntity <OrganizationInfo>(x => x.Id == application.OrganizationInfoId) .FirstOrDefault(); if (orgInfo == null) { throw new Exception(); } var limsLicense = (await _limsExchangeService.GetLicenses("Prl", string.IsNullOrEmpty(organization.EDRPOU) ? organization.INN : organization.EDRPOU)).FirstOrDefault(); var newLic = new PrlLicense { OldLimsId = limsLicense.Id, OrgUnitId = application.OrgUnitId, ParentId = application.Id, LicType = "PRL", LicState = "Active", IsRelevant = true, LicenseDate = DateTime.Parse(limsLicense.RegistrationDate), OrderDate = limsLicense.OrderDate, OrderNumber = limsLicense.OrderNumber }; DataService.Add(newLic); application.AppState = "Reviewed"; application.BackOfficeAppState = "Reviewed"; orgInfo.IsActualInfo = true; orgInfo.IsPendingLicenseUpdate = false; var decision = new AppDecision { Id = Guid.NewGuid(), AppId = appId, DecisionType = "Accepted", DecisionDescription = text }; application.AppDecisionId = decision.Id; DataService.Add(decision); await DataService.SaveChangesAsync(); }
public void ProcessApplicationToLicense(Guid appId) { var application = _dataService.GetEntity <PrlApplication>(prlApplication => prlApplication.Id == appId) .FirstOrDefault(); if (application == null) { throw new NullReferenceException("Заяву не знайдено"); } //создание обьекта лицензии var license = new PrlLicense(); _objectMapper.Map(application, license); license.Id = Guid.NewGuid(); //ссылка на дочернюю заяву, из которой создана лицензия license.ParentId = application.Id; var licenseBranches = new List <Branch>(); var licenseBranch = new List <ApplicationBranch>(); var applicationBranchesIds = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == appId).Select(x => x.BranchId).Distinct(); var applicationBranches = _dataService.GetEntity <Branch>(br => applicationBranchesIds.Contains(br.Id)); foreach (var branch in applicationBranches) { var licBr = _objectMapper.Map <Branch>(branch); licBr.Id = Guid.NewGuid(); //ссылка на дочерний обьект мпд licBr.ParentId = branch.Id; licenseBranches.Add(licBr); licenseBranch.Add(new ApplicationBranch { BranchId = licBr.Id, LimsDocumentId = license.Id }); } var applicationAssigneeBranches = _dataService.GetEntity <AppAssigneeBranch>(x => applicationBranchesIds.Contains(x.BranchId)); var applicationAssigneeIds = applicationAssigneeBranches.Select(x => x.AssigneeId).Distinct(); var applicationAssignee = _dataService.GetEntity <AppAssignee>(x => applicationAssigneeIds.Contains(x.Id)); var licenseAssigneeBranches = new List <AppAssigneeBranch>(); var licenseAssignees = new List <AppAssignee>(); foreach (var assignee in applicationAssignee) { var licAssignee = _objectMapper.Map <AppAssignee>(assignee); licAssignee.Id = Guid.NewGuid(); licenseAssignees.Add(licAssignee); var assBranches = applicationAssigneeBranches.Where(x => x.AssigneeId == assignee.Id); foreach (var appAssigneeBranch in assBranches) { licenseAssigneeBranches.Add(new AppAssigneeBranch { AssigneeId = licAssignee.Id, BranchId = applicationBranches.FirstOrDefault(br => br.ParentId == appAssigneeBranch.BranchId) .Id }); } } var applicationContractorBranches = _dataService.GetEntity <PrlBranchContractor>(x => applicationBranchesIds.Contains(x.BranchId)); var applicaitonContractorIds = applicationContractorBranches.Select(x => x.ContractorId).Distinct(); var applicationContractors = _dataService.GetEntity <PrlContractor>(x => applicaitonContractorIds.Contains(x.Id)); var licenseContractorBranches = new List <PrlBranchContractor>(); var licenseContractors = new List <PrlContractor>(); foreach (var applicationContractor in applicationContractors) { var licContractor = _objectMapper.Map <PrlContractor>(applicationContractor); licContractor.Id = Guid.NewGuid(); licenseContractors.Add(licContractor); var cntBranches = applicationContractorBranches.Where(x => x.ContractorId == applicationContractor.Id); foreach (var prlBranchContractor in cntBranches) { licenseContractorBranches.Add(new PrlBranchContractor { ContractorId = licContractor.Id, BranchId = applicationBranches.FirstOrDefault(br => br.ParentId == prlBranchContractor.BranchId) .Id }); } } _dataService.Add(license); licenseBranches.ForEach(branch => _dataService.Add(branch)); licenseContractors.ForEach(contractor => _dataService.Add(contractor)); licenseContractorBranches.ForEach(contractorBr => _dataService.Add(contractorBr)); licenseAssignees.ForEach(assignee => _dataService.Add(assignee)); licenseAssigneeBranches.ForEach(assigneeBr => _dataService.Add(assigneeBr)); }
public void CreateLicenseFromApplication(AppDecision decision, AppProtocol protocol) { var application = _dataService.GetEntity <PrlApplication>(prlApplication => prlApplication.Id == decision.AppId) .FirstOrDefault(); long id = 0; if (application == null) { Log.Error("CreateLicenseFromApplication - Заяву не знайдено"); return; } var oldLicense = _dataService .GetEntity <PrlLicense>(x => x.OrgUnitId == application.OrgUnitId && x.LicState == "Active" && x.IsRelevant) .FirstOrDefault(); try { if (decision == null) { Log.Error("CreateLicenseFromApplication - Рішення не знайдено"); application.ErrorProcessingLicense = "Рішення не знайдено"; throw new Exception(); } decision.IsClosed = true; _dataService.SaveChanges(); if (protocol == null) { Log.Error("CreateLicenseFromApplication - Протокол не знайдено"); application.ErrorProcessingLicense = "Протокол не знайдено"; throw new Exception(); } if (application.AppSort == "GetLicenseApplication" || application.AppSort == "IncreaseToPRLApplication") { if (oldLicense != null) { Log.Error("CreateLicenseFromApplication - У даного СГД вже є активна ліцензія"); application.ErrorProcessingLicense = "У даного СГД вже є активна ліцензія"; throw new Exception(); } } else { if (oldLicense == null) { Log.Error("CreateLicenseFromApplication - У даного СГД немає активної ліцензії"); application.ErrorProcessingLicense = "У даного СГД немає активної ліцензії"; throw new Exception(); } oldLicense.IsRelevant = false; id = oldLicense.OldLimsId; } } catch (Exception) { _dataService.SaveChanges(); return; } long limsId; if (application.AppSort == "GetLicenseApplication" || application.AppSort == "IncreaseToPRLApplication" || application.AppSort == "CancelLicenseApplication" || application.AppSort == "DecreasePRLApplication" || application.AppSort == "AddBranchApplication" || application.AppSort == "RemBranchApplication" || application.AppSort == "ChangeAutPersonApplication" || application.AppSort == "AddBranchInfoApplication" || application.AppSort == "RemBranchInfoApplication" || application.AppSort == "ChangeContrApplication" ) { try { limsId = _limsExchangeService.InsertLicense(decision.AppId).Result; } catch (Exception e) { Log.Error(e.Message); return; } } else { //lims insert for other sorts of application limsId = id;//id of new limsDoc } var newLicense = new PrlLicense { OldLimsId = limsId, OrgUnitId = application.OrgUnitId, Id = Guid.NewGuid(), ParentId = application.Id, LicType = "PRL", LicState = "Active", IsRelevant = true, LicenseDate = decision.DateOfStart, OrderNumber = protocol.OrderNumber, OrderDate = protocol.OrderDate.Value }; switch (application.AppSort) { case "RemBranchApplication": { var appBranches = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == application.Id).Select(x => x.BranchId).ToList(); var branches = _dataService.GetEntity <Branch>(x => appBranches.Contains(x.Id) && x.LicenseDeleteCheck == true).ToList(); branches.ForEach(x => x.RecordState = RecordState.D); branches.ForEach(x => x.BranchActivity = "Closed"); break; } case "CancelLicenseApplication": case "DecreasePRLApplication": newLicense.LicState = "Canceled"; break; case "AddBranchInfoApplication": { var appBranches = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == application.Id) .Select(x => x.BranchId).ToList(); var branches = _dataService .GetEntity <Branch>(x => appBranches.Contains(x.Id)).ToList(); foreach (var branch in branches) { List <Dictionary <string, string> > operationListForm; try { operationListForm = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >( branch.OperationListForm); } catch (Exception) { operationListForm = new List <Dictionary <string, string> >(); } List <Dictionary <string, string> > operationListFormChanging; try { operationListFormChanging = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >( branch.OperationListFormChanging); } catch (Exception) { operationListFormChanging = new List <Dictionary <string, string> >(); } foreach (var itemChanging in operationListFormChanging) { var exists = false; var itemValueChanging = itemChanging.FirstOrDefault().Value; foreach (var item in operationListForm) { var itemValue = item.FirstOrDefault().Value; if (itemValueChanging == itemValue) { exists = true; break; } } if (exists == false) { operationListForm.Add(itemChanging); } } branch.OperationListForm = JsonConvert.SerializeObject(operationListForm.OrderBy(x => x.FirstOrDefault().Value)); branch.OperationListFormChanging = null; } break; } case "RemBranchInfoApplication": { var appBranches = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == application.Id) .Select(x => x.BranchId).ToList(); var branches = _dataService .GetEntity <Branch>(x => appBranches.Contains(x.Id)).ToList(); foreach (var branch in branches) { List <Dictionary <string, string> > operationListForm; try { operationListForm = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >( branch.OperationListForm); } catch (Exception) { operationListForm = new List <Dictionary <string, string> >(); } List <Dictionary <string, string> > operationListFormChanging; try { operationListFormChanging = JsonConvert.DeserializeObject <List <Dictionary <string, string> > >( branch.OperationListFormChanging); } catch (Exception) { operationListFormChanging = new List <Dictionary <string, string> >(); } foreach (var itemChanging in operationListFormChanging) { var itemValueChanging = itemChanging.FirstOrDefault().Value; for (int i = operationListForm.Count - 1; i >= 0; i--) { var itemValue = operationListForm[i].FirstOrDefault().Value; if (itemValue == itemValueChanging) { operationListForm.RemoveAt(i); } } } branch.OperationListForm = JsonConvert.SerializeObject(operationListForm); branch.OperationListFormChanging = null; } break; } } _dataService.Add(newLicense); application.AppState = "Reviewed"; application.BackOfficeAppState = "Reviewed"; _dataService.SaveChanges(); }