public async Task <IActionResult> EditAdditionForLicense(Guid?id) { PrlAppDetailDTO model = null; if (id == null || id == Guid.Empty) { model = new PrlAppDetailDTO(); var license = (await _limsExchangeService.GetLicenses("PRL", string.IsNullOrEmpty(_userInfo?.EDRPOU()) ? _userInfo.INN() : _userInfo.EDRPOU())).FirstOrDefault(); model.AppSort = "AdditionalInfoToLicense"; model.OwnershipType = license.OwnershipType; model.LegalFormType = license.LegalFormType; if (!string.IsNullOrEmpty(_userInfo?.EDRPOU())) { model.EDRPOU = _userInfo?.EDRPOU(); model.OrgDirector = license.OrgDirector; model.OrgName = license.OrganizationName; } else { model.INN = _userInfo?.INN(); model.OrgName = license.OrganizationName; } } else { model = (await _dataService.GetDtoAsync <PrlAppDetailDTO>(x => x.Id == id)).FirstOrDefault(); } return(View("Edit", model)); }
public async Task SubmitAdditionalInfoToLicense(Guid appId, string text) { var application = DataService.GetEntity <TrlApplication>(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("Trl", string.IsNullOrEmpty(organization.EDRPOU) ? organization.INN : organization.EDRPOU)).FirstOrDefault(); var newLic = new TrlLicense { OldLimsId = limsLicense.Id, OrgUnitId = application.OrgUnitId, ParentId = application.Id, LicType = "Trl", 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 (Guid organizationId, Guid employeeId, Guid profileId, Guid personId) SaveSignIn(SignInEditModel model, string path) { var organization = new OrganizationExt(); if (!string.IsNullOrEmpty(model.EDRPOU)) { organization = _context.Organizations.FirstOrDefault(x => x.EDRPOU == model.EDRPOU); } else { organization = null; } if (organization == null) { organization = new OrganizationExt { Name = model.Name, EDRPOU = model.EDRPOU, EMail = model.OrgEmail, INN = !string.IsNullOrEmpty(model.EDRPOU) ? null : model.INN }; _context.Add_Auditable(organization); _context.SaveChanges(); var licenses = _limsService.GetLicenses("", !string.IsNullOrEmpty(model.EDRPOU) ? model.EDRPOU : model.INN).Result; var trlLicenseIds = new List <string> { "2", "3", "4" }; var orgInfoPRL = new OrganizationInfo() { Name = model.Name, Type = "PRL", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Contains("1")) }; var orgInfoIML = new OrganizationInfo() { Name = model.Name, Type = "IML", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.FirstOrDefault(x => x.LicenseTypesIds.Contains("5")) != null }; var orgInfoTRL = new OrganizationInfo() { Name = model.Name, Type = "TRL", OrganizationId = organization.Id, IsActualInfo = true, IsPendingLicenseUpdate = licenses.Any(x => x.LicenseTypesIds.Split("|").Any(y => trlLicenseIds.Contains(y))) }; _context.AddRange_Auditable(orgInfoPRL, orgInfoIML, orgInfoTRL); _context.SaveChanges(); //TODO email } var person = _context.Person.FirstOrDefault(x => x.IPN == model.INN && x.LastName == model.LastName); if (person == null) { person = new Person { LastName = model.LastName, MiddleName = model.MiddleName, Name = model.UserName, Phone = model.UserPhone, IPN = model.INN, Email = model.UserEmail, Birthday = DateTime.MinValue, Caption = $"{model.LastName} {model.UserName} {model.MiddleName}" }; _context.Add_Auditable(person); _context.SaveChanges(); } var employees = _context.EmployeesExt.Where(x => x.PersonId == person.Id) .Include(x => x.DefaultValues) .Include(x => x.Profiles) .ToList(); var employeeOrg = employees.FirstOrDefault(x => x.OrganizationId == organization.Id); var profile = _context.Profiles.FirstOrDefault(x => x.Caption == "Employee"); if (employeeOrg != null) { employeeOrg.Position = model.Position; employeeOrg.UserEmail = model.UserEmail; employeeOrg.ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage; employeeOrg.ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage; employeeOrg.ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication; employeeOrg.ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication; employeeOrg.PersonalCabinetStatus = model.PersonalCabinetStatus; employeeOrg.ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo; employeeOrg.ReceiveOnOverduePayment = model.ReceiveOnOverduePayment; try { if (employeeOrg.DefaultValues.FirstOrDefault()?.ValueId != organization.Id) { employeeOrg.DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }; } } catch (Exception) { if (employeeOrg.DefaultValues.Any()) { employeeOrg.DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }; } } if (employeeOrg.Profiles.Any()) { employeeOrg.Profiles = new List <UserProfile> { new UserProfile { ProfileId = profile.Id, Caption = $"{profile.Caption}: {person.Caption}" } }; } _context.SaveChanges(); if (employeeOrg.UserEmail != model.UserEmail) { //TODO Email } } else { employeeOrg = new EmployeeExt { PersonId = person.Id, Position = model.Position, UserEmail = model.UserEmail, ReceiveOnChangeAllApplication = model.ReceiveOnChangeAllApplication, ReceiveOnChangeAllMessage = model.ReceiveOnChangeAllMessage, ReceiveOnChangeOwnApplication = model.ReceiveOnChangeOwnApplication, ReceiveOnChangeOwnMessage = model.ReceiveOnChangeOwnMessage, PersonalCabinetStatus = model.PersonalCabinetStatus, ReceiveOnChangeOrgInfo = model.ReceiveOnChangeOrgInfo, ReceiveOnOverduePayment = model.ReceiveOnOverduePayment, OrganizationId = organization.Id, DefaultValues = new List <UserDefaultValue> { new UserDefaultValue { Caption = person.Caption, EntityName = nameof(OrganizationExt), ValueId = organization.Id } }, Profiles = new List <UserProfile> { new UserProfile { ProfileId = profile.Id, Caption = $"{profile.Caption}: {person.Caption}" } } }; _context.Add_Auditable(employeeOrg); _context.SaveChanges(); //TODO Email } return(organization.Id, employeeOrg.Id, profile.Id, person.Id); }
public async Task <Guid> SaveApplication(PrlAppDetailDTO editModel, bool isBackOffice) { Guid appId; var userInfo = await _userInfoService?.GetCurrentUserInfoAsync(); var isNew = false; if (editModel.Id == Guid.Empty) { isNew = true; var model = new PrlAppDetailDTO(); _objectMapper.Map(editModel, model); if (model.OrgUnitId == Guid.Empty) { model.OrgUnitId = new Guid(userInfo.OrganizationId()); } if (isBackOffice) { model.IsCreatedOnPortal = false; model.BackOfficeAppState = "Project"; } else { model.AppState = "Project"; model.IsCreatedOnPortal = true; } model.AppType = "PRL"; var organizationInfo = new OrganizationInfo(); organizationInfo.OrganizationId = model.OrgUnitId == Guid.Empty ? new Guid(userInfo?.OrganizationId()) : model.OrgUnitId; organizationInfo.Type = "PRL"; if (string.IsNullOrEmpty(model.EDRPOU)) { if (isBackOffice == false) { organizationInfo.OrgDirector = userInfo.FullName(); } } else { organizationInfo.OrgDirector = model.OrgDirector; } organizationInfo.Name = model.OrgName; organizationInfo.EMail = model.EMail; organizationInfo.LegalFormType = model.LegalFormType; organizationInfo.OwnershipType = model.OwnershipType; organizationInfo.PhoneNumber = model.PhoneNumber; organizationInfo.FaxNumber = model.FaxNumber; organizationInfo.NationalAccount = model.NationalAccount; organizationInfo.InternationalAccount = model.InternationalAccount; organizationInfo.NationalBankRequisites = model.NationalBankRequisites; organizationInfo.InternationalBankRequisites = model.InternationalBankRequisites; organizationInfo.PassportSerial = model.PassportSerial; organizationInfo.PassportNumber = model.PassportNumber; organizationInfo.PassportDate = model.PassportDate; organizationInfo.PassportIssueUnit = model.PassportIssueUnit; organizationInfo.AddressId = model.AddressId; var license = _prlLicenseService.GetLicenseGuid(model.OrgUnitId); if (license == null) { if (editModel.AppSort == "AdditionalInfoToLicense") { organizationInfo.IsPendingLicenseUpdate = true; } organizationInfo.IsActualInfo = true; DataService.GetEntity <OrganizationInfo>(x => x.IsActualInfo && x.OrganizationId == model.OrgUnitId && x.Type == "PRL").ToList() .ForEach(x => x.IsActualInfo = false); } DataService.Add(organizationInfo); DataService.SaveChanges(); model.OrganizationInfoId = organizationInfo.Id; var organization = DataService.GetEntity <OrganizationExt>() .SingleOrDefault(x => x.Id == model.OrgUnitId); if (string.IsNullOrEmpty(model.EDRPOU)) { organization.INN = model.INN; } // Тут работал Макс // organization.EMail = model.EMail; appId = DataService.Add <PrlApplication>(model); await DataService.SaveChangesAsync(); } else { if (isBackOffice) { editModel.IsCreatedOnPortal = false; editModel.BackOfficeAppState = "Project"; } else { editModel.AppState = "Project"; editModel.IsCreatedOnPortal = true; } var organizationInfo = DataService.GetEntity <OrganizationInfo>() .SingleOrDefault(x => x.Id == editModel.OrganizationInfoId); organizationInfo.LegalFormType = editModel.LegalFormType; organizationInfo.OwnershipType = editModel.OwnershipType; organizationInfo.PhoneNumber = editModel.PhoneNumber; organizationInfo.FaxNumber = editModel.FaxNumber; organizationInfo.NationalAccount = editModel.NationalAccount; organizationInfo.InternationalAccount = editModel.InternationalAccount; organizationInfo.NationalBankRequisites = editModel.NationalBankRequisites; organizationInfo.InternationalBankRequisites = editModel.InternationalBankRequisites; organizationInfo.PassportSerial = editModel.PassportSerial; organizationInfo.PassportNumber = editModel.PassportNumber; organizationInfo.PassportDate = editModel.PassportDate; organizationInfo.PassportIssueUnit = editModel.PassportIssueUnit; organizationInfo.OrgDirector = editModel.OrgDirector; organizationInfo.AddressId = editModel.AddressId; organizationInfo.EMail = editModel.EMail; // Тут работал Макс // var organization = DataService.GetEntity<OrganizationExt>().SingleOrDefault(x => x.Id == editModel.OrgUnitId); // organization.EMail = editModel.EMail; appId = DataService.Add <PrlApplication>(editModel); await DataService.SaveChangesAsync(); } if (editModel.AppSort == "AdditionalInfoToLicense" && isNew) { var license = (await _limsExchangeService .GetLicenses("PRL", string.IsNullOrEmpty(editModel.EDRPOU) ? editModel.INN : editModel.EDRPOU)).FirstOrDefault(); if (license == null) { throw new Exception(); } foreach (var branchLicense in license.Branches) { var branch = new Branch { Id = Guid.NewGuid(), OrganizationId = editModel.OrgUnitId == Guid.Empty ? new Guid(userInfo?.OrganizationId()) : editModel.OrgUnitId, OldLimsId = branchLicense.Id, Name = branchLicense.Name }; var branchId = DataService.Add(branch, false); var appBranch = new ApplicationBranch() { LimsDocumentId = appId, BranchId = branchId }; DataService.Add(appBranch, false); await DataService.SaveChangesAsync(); } ; } return(appId); }