public void Synchronize() { var csvFiles = _fileMan.GetSondeCsvFiles(); if (!csvFiles.Any()) { Log.Info($"No sonde csv files in '{_fileMan.SondeFileFolder}'"); return; } using (var client = new ImportClient(_context)) { foreach (var fileInfo in csvFiles) { try { SynchronizeOneFile(fileInfo, client); } catch (Exception ex) { Log.Error($"Failed to process sonde file '{fileInfo.FullName}'.{ex.Message}"); } } } }
private void SynchronizeOneFile(FileInfo fileInfo, ImportClient client) { var fileSet = new FileInfoSet(fileInfo); fileSet.ProcessingSondeFile = _fileMan.MoveToProcessing(fileInfo); fileSet.ConvertedSamplesFile = _converter.ToSamplesObservationFile(fileSet.ProcessingSondeFile); Log.Info($"Transformed successfully:'{fileSet.ConvertedSamplesFile.Name}'"); try { var dryRunResult = DryRunImport(fileSet, client); if (dryRunResult.HasErrors) { return; } var importResult = RunImport(fileSet, client); if (importResult.HasErrors) { return; } _fileMan.MoveAllToSuccessNoThrow(fileSet.ProcessingSondeFile, fileSet.ConvertedSamplesFile); } catch (Exception ex) { Log.Error($"Failed to import '{fileSet.ProcessingSondeFile.Name}'. Error: {ex.Message}"); _fileMan.MoveAllToFailedNoThrow(fileSet.ProcessingSondeFile, fileSet.ConvertedSamplesFile); } }
private async Task <Result> ImportCellphone(ScopeOptions scope, ImportClient data, ClientEdit client) { var result = new Result(true); if (string.IsNullOrEmpty(data.Cellphone)) { return(result); } //Clean data.Cellphone = data.Cellphone.TrimWhiteSpace().Replace("-", ""); //See if email exits var email = await _contactService.GetContact(scope, client.Id.Value, data.Cellphone); if (email == null) { var contact = new Contact() { ClientId = client.Id, Value = data.Cellphone, ContactTypeId = ContactType.CONTACT_TYPE_CELLPHONE }; result = await _contactService.InsertContact(scope, contact); } return(result); }
private async Task <Result> ImportEmail(ScopeOptions scope, ImportClient data, ClientEdit client) { var result = new Result(true); if (string.IsNullOrEmpty(data.Email)) { return(result); } //See if email exits var email = await _contactService.GetContact(scope, client.Id.Value, data.Email); if (email == null) { var contact = new Contact() { ClientId = client.Id, Value = data.Email, ContactTypeId = ContactType.CONTACT_TYPE_EMAIL }; result = await _contactService.InsertContact(scope, contact); } return(result); }
public async Task ImportClient_Update_LastNameAndDateOfBirth() { var options = TestHelper.GetDbContext("ImportClient_Update_LastNameAndDateOfBirth"); var user1 = TestHelper.InsertUserDetailed(options); var mem1 = new ClientEntity { Id = Guid.NewGuid(), ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, OrganisationId = user1.Organisation.Id }; var mem2 = new ClientEntity { Id = Guid.NewGuid(), ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, FirstName = "FN 1", LastName = "van Jones", IdNumber = "8210035032082", DateOfBirth = new DateTime(1982, 10, 3), OrganisationId = user1.Organisation.Id }; using (var context = new DataContext(options)) { context.Client.Add(mem1); context.Client.Add(mem2); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { FirstName = "FN 1 Updated", LastName = mem2.LastName, DateOfBirth = mem2.DateOfBirth }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == mem2.IdNumber); Assert.Equal(data.FirstName, actual.FirstName); } }
public async Task ImportClient_Insert_With3MissingZeroOnIdNumber() { var options = TestHelper.GetDbContext("ImportClient_Insert_With3MissingZeroOnIdNumber"); var user1 = TestHelper.InsertUserDetailed(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "7287372085" //missing leading zero }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == "0007287372085"); Assert.NotNull(actual); } }
public async Task ImportClient_Insert_WithAlternateIdNumber() { var options = TestHelper.GetDbContext("ImportClient_Insert_WithAlternateIdNumber"); var user1 = TestHelper.InsertUserDetailed(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "123456" //Not a valid id number so should be treated as a passport number }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.AlternateIdNumber == data.IdNumber); Assert.Null(actual.IdNumber); } }
private static async Task TransferRegistryArtifacts(Options options) { var exportOptionsDisplay = options.ExportPipeline.Options != null?string.Join(", ", options.ExportPipeline.Options) : ""; var importOptionsDisplay = options.ImportPipeline.Options != null?string.Join(", ", options.ImportPipeline.Options) : ""; Console.WriteLine($"Starting ContainerRegistryTransfer..."); Console.WriteLine(); Console.WriteLine($"Azure Environment properties:"); Console.WriteLine($" MIClientId: {options.MIClientId}"); Console.WriteLine($" SPClientId: {options.SPClientId}"); Console.WriteLine($" AzureEnvironment: {options.AzureEnvironment.Name}"); Console.WriteLine($" SubscriptionId: {options.SubscriptionId}"); Console.WriteLine($"======================================================================"); Console.WriteLine($"ExportPipeline properties:"); Console.WriteLine($" ResourceGroupName: {options.ExportPipeline.ResourceGroupName}"); Console.WriteLine($" RegistryName: {options.ExportPipeline.RegistryName}"); Console.WriteLine($" ExportPipelineName: {options.ExportPipeline.PipelineName}"); Console.WriteLine($" UserAssignedIdentity: {options.ExportPipeline.UserAssignedIdentity}"); Console.WriteLine($" StorageUri: {options.ExportPipeline.ContainerUri}"); Console.WriteLine($" KeyVaultSecretUri: {options.ExportPipeline.KeyVaultUri}"); Console.WriteLine($" Options: {exportOptionsDisplay}"); Console.WriteLine($"======================================================================"); Console.WriteLine($"ImportPipeline properties:"); Console.WriteLine($" ResourceGroupName: {options.ImportPipeline.ResourceGroupName}"); Console.WriteLine($" RegistryName: {options.ImportPipeline.RegistryName}"); Console.WriteLine($" ImportPipelineName: {options.ImportPipeline.PipelineName}"); Console.WriteLine($" UserAssignedIdentity: {options.ImportPipeline.UserAssignedIdentity}"); Console.WriteLine($" StorageUri: {options.ImportPipeline.ContainerUri}"); Console.WriteLine($" KeyVaultSecretUri: {options.ImportPipeline.KeyVaultUri}"); Console.WriteLine($" Options: {importOptionsDisplay}"); Console.WriteLine($"======================================================================"); Console.WriteLine(); var registryClient = AzureHelper.GetContainerRegistryManagementClient(options); var keyVaultClient = AzureHelper.GetKeyVaultManagementClient(options); var exportClient = new ExportClient(registryClient, keyVaultClient, options); var exportPipeline = await exportClient.CreateExportPipelineAsync().ConfigureAwait(false); var importClient = new ImportClient(registryClient, keyVaultClient, options); var importPipeline = await importClient.CreateImportPipelineAsync().ConfigureAwait(false); Console.WriteLine(); Console.WriteLine($"======================================================================"); Console.WriteLine($"Your importPipeline '{importPipeline.Name}' will run automatically."); Console.WriteLine($"Would you like to run your exportPipeline '{options.ExportPipeline.PipelineName}'? [Y/N]"); var response = Console.ReadLine(); if (string.Equals("Y", response, StringComparison.InvariantCultureIgnoreCase)) { Console.WriteLine("Validating pipelineRun configurations for export."); options.ExportPipelineRun.Validate(); await exportClient.ExportImagesAsync(exportPipeline).ConfigureAwait(false); } Console.WriteLine("ContainerRegistryTransfer completed. Goodbye!"); }
private PolicyEdit MapPolicyProperties(PolicyEdit policy, ImportClient data, Guid userId, List <PolicyType> policyTypes) { policy.UserId = userId; policy.Premium = data.PolicyPremium != null ? data.PolicyPremium : policy.Premium; policy.StartDate = data.PolicyStartDate != null ? data.PolicyStartDate : policy.StartDate; policy.PolicyTypeId = GetPolicyTypeId(data.PolicyTypeCode, policyTypes); return(policy); }
private ClientEdit LoadClientType(ClientEdit client, ImportClient data) { //If there is no id number but there is a policy number then set client type to Unknown. if (string.IsNullOrWhiteSpace(data.IdNumber) && !string.IsNullOrWhiteSpace(data.PolicyNumber)) { client.ClientTypeId = ClientType.CLIENT_TYPE_UNKNOWN_ENTITY; } return(client); }
private ImportResult GetImportResultWithAction(ImportClient client, Func <string> importFunc) { var statusUrl = importFunc(); var status = client.GetImportStatusUntilComplete(statusUrl); var response = client.GetResult(status.ResultUri.ToString()); return(new ImportResult { ImportStatus = status, ResultResponse = response }); }
public async Task ImportClient_InsertPolicy_CheckUserAlias() { var options = TestHelper.GetDbContext("ImportClient_InsertPolicy_CheckUserAlias"); var organisation = TestHelper.InsertOrganisation(options); var user = new UserEdit { Id = Guid.NewGuid(), FirstName = "Dean", LastName = "van Niekerk", Aliases = new List <string>() { "DJVANNiekerk" } }; var user1 = TestHelper.InsertUserDetailed(options, organisation, user); var company = TestHelper.InsertCompany(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var policyService = new PolicyService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "12345", LastName = "LN", PolicyNumber = "987654", PolicyCompanyId = company.Id, PolicyUserFullName = "DjvanNiekerk" }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Policy.FirstOrDefaultAsync(m => m.Number == data.PolicyNumber); Assert.Equal(data.PolicyCompanyId, actual.CompanyId); Assert.Equal(user1.User.Id, actual.UserId); } }
private ClientEdit MapClientProperties(ClientEdit client, ImportClient data, List <ClientType> clientTypes) { client.ClientTypeId = GetClientTypeId(data.ClientTypeCode, client, clientTypes); client.FirstName = data.FirstName != null ? data.FirstName : client.FirstName; client.LastName = data.LastName != null ? data.LastName : client.LastName; client.Initials = data.FirstName != null?data.FirstName.Acronym() : client.Initials; client.TaxNumber = data.TaxNumber != null ? data.TaxNumber : client.TaxNumber; client.DateOfBirth = data.DateOfBirth != null ? data.DateOfBirth : client.DateOfBirth; return(client); }
private void ReportImportFailed(ImportClient client, ImportResultResponse result, FileInfoSet fileSet) { Log.Error($"'{fileSet.OriginalSondeFile.Name}': {result.errorCount} errors found."); var invalidCsvText = client.GetContentWithoutAuthorizationHeader(result.invalidRowsCsvUrl); var failedFileInfo = _fileMan.GetFailedSamplesFileInfo(fileSet.OriginalSondeFile); _fileMan.SaveToFailedFolder(invalidCsvText, failedFileInfo); Log.Info($"Errors saved to 'Failed' folder:'{failedFileInfo.Name}'"); _fileMan.MoveAllToFailedNoThrow(fileSet.ProcessingSondeFile, fileSet.ConvertedSamplesFile); }
public async Task ImportClient_Update_MatchOnShortIdNumber() { var options = TestHelper.GetDbContext("ImportClient_Update_MatchOnShortIdNumber"); var user1 = TestHelper.InsertUserDetailed(options); var user2 = TestHelper.InsertUserDetailed(options, user1.Organisation); var mem = new ClientEntity { Id = Guid.NewGuid(), ClientTypeId = ClientType.CLIENT_TYPE_INDIVIDUAL, LastName = "LN 1", IdNumber = "8201015800184", OrganisationId = user1.Organisation.Id }; using (var context = new DataContext(options)) { context.Client.Add(mem); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "8201015800085", LastName = "LN updated", }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.Id == mem.Id); Assert.Equal(user1.Organisation.Id, actual.OrganisationId); Assert.Equal(data.LastName, actual.LastName); } }
public async Task Insert() { var client = new ImportClient() { IdNumber = "0", FirstName = "1", LastName = "2", Email = "3", Cellphone = "4", TaxNumber = "5", DateOfBirth = DateTime.Now, PolicyNumber = "6", PolicyCompanyId = Guid.NewGuid(), PolicyUserFullName = "7", PolicyPremium = 1, PolicyTypeCode = "8", PolicyStartDate = DateTime.Now, ClientTypeCode = "9", }; var service = new Mock <IClientImportService>(); var authService = TestHelper.MockAuthenticationService(Scope.Branch); var result = new Result() { Success = true }; ScopeOptions options = null; ImportClient inserted = null; service.Setup(c => c.ImportClient(It.IsAny <ScopeOptions>(), It.Is <ImportClient>(m => m == client))) .Callback((ScopeOptions o, ImportClient i) => { inserted = i; options = o; }) .ReturnsAsync(result); var controller = new ImportController(service.Object, authService.Object); var actual = await controller.Import(client); Assert.Same(client, inserted); Assert.Equal(Scope.Branch, options.Scope); var okResult = Assert.IsType <OkObjectResult>(actual); var returnValue = Assert.IsType <Result>(okResult.Value); Assert.Same(result, returnValue); }
public async Task ImportClient_InsertPolicy() { var options = TestHelper.GetDbContext("ImportClient_InsertPolicy"); var user1 = TestHelper.InsertUserDetailed(options); var policyType1 = TestHelper.InsertPolicyType(options); var policyType2 = TestHelper.InsertPolicyType(options); var company = TestHelper.InsertCompany(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var policyService = new PolicyService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "12345", LastName = "LN", PolicyNumber = "987654", PolicyCompanyId = company.Id, PolicyTypeCode = policyType2.Code, PolicyPremium = 5000, PolicyStartDate = DateTime.Now, PolicyUserFullName = $"{user1.User.FirstName} {user1.User.LastName}" }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Policy.FirstOrDefaultAsync(m => m.Number == data.PolicyNumber); Assert.Equal(data.PolicyCompanyId, actual.CompanyId); Assert.Equal(user1.User.Id, actual.UserId); Assert.Equal(data.PolicyPremium, actual.Premium); Assert.Equal(data.PolicyStartDate, actual.StartDate); Assert.Equal(policyType2.Id, actual.PolicyTypeId); } }
public async Task ImportClient_Update_WithAlternateIdNumber() { var options = TestHelper.GetDbContext("ImportClient_Update_WithAlternateIdNumber"); var user1 = TestHelper.InsertUserDetailed(options); var mem = new ClientEntity { Id = Guid.NewGuid(), FirstName = "FN 1", LastName = "LN 1", AlternateIdNumber = "123456", OrganisationId = user1.Organisation.Id }; using (var context = new DataContext(options)) { context.Client.Add(mem); context.SaveChanges(); } using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "123456", //Not a valid id number so should be treated as a passport number LastName = "LN updated" }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.AlternateIdNumber == data.IdNumber); Assert.Equal(data.LastName, actual.LastName); } }
public async Task <IActionResult> Import([FromBody] ImportClient client) { var scope = AuthenticationService.GetScope(User); var result = await ClientImportService.ImportClient(scope, client); result.Tag = null; if (!result.Success) { return(BadRequest(result.ValidationFailures)); } return(Ok(result)); }
void LoadData() { ImportClient client = new ImportClient("NetHttpBinding_IImport"); client.Open(); srcLst = new BindingList <ImportStaging>(client.getAllData()); client.Close(); var filter = srcLst? .Where(_ => (int)cmbAction.SelectedValue == ~0 ? true : _.Action == (int)cmbAction.SelectedValue) .Where(_ => (int)cmbModule.SelectedValue == ~0 ? true : _.Module == (int)cmbModule.SelectedValue) .Where(_ => (int)cmbStatus.SelectedValue == ~0 ? true : _.Status == (int)cmbStatus.SelectedValue) .ToList(); dataGridView1.DataSource = filter; dataGridView1.Columns["Data"].Visible = false; }
private ImportResult DryRunImport(FileInfoSet fileSet, ImportClient client) { Log.Info($"Trying to import '{fileSet.ConvertedSamplesFile.Name}'..."); var dryRunResult = GetImportResultWithAction(client, () => client.PostImportDryRunForStatusUrl(fileSet.ConvertedSamplesFile)); if (!dryRunResult.HasErrors) { return(dryRunResult); } ReportImportFailed(client, dryRunResult.ResultResponse, fileSet); return(dryRunResult); }
public async Task ImportClient_Update_MatchOnPolicyNumber() { var options = TestHelper.GetDbContext("ImportClient_Update_MatchOnPolicyNumber"); var user1 = TestHelper.InsertUserDetailed(options); var user2 = TestHelper.InsertUserDetailed(options, user1.Organisation); var client2 = TestHelper.InsertClient(options, user1.Organisation); var client1 = TestHelper.InsertClient(options, user1.Organisation, "8210035032082"); var company = TestHelper.InsertCompany(options); var policy2 = TestHelper.InsertPolicy(options, client2, user1, company.Id); var policy1 = TestHelper.InsertPolicy(options, client1, user1, company.Id); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var policyService = new PolicyService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, policyService, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "", LastName = "LN updated", PolicyNumber = policy1.Number, PolicyCompanyId = company.Id, PolicyUserFullName = user1.User.FirstName + " " + user1.User.LastName }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.Id == client1.Client.Id); Assert.Equal(user1.Organisation.Id, actual.OrganisationId); Assert.Equal(data.LastName, actual.LastName); } }
public async Task ImportClient_Insert() { var options = TestHelper.GetDbContext("ImportClient_Insert"); var user1 = TestHelper.InsertUserDetailed(options); var clientType = TestHelper.InsertClientTypeIndividual(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "821003 5032 082", FirstName = "FN", LastName = "LN", TaxNumber = "987654", DateOfBirth = DateTime.Now, ClientTypeCode = clientType.Code }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == "8210035032082"); Assert.Null(actual.AlternateIdNumber); Assert.Equal(clientType.Id, actual.ClientTypeId); Assert.Equal(user1.Organisation.Id, actual.OrganisationId); Assert.Equal(data.LastName, actual.LastName); Assert.Equal(data.FirstName, actual.FirstName); Assert.Equal(data.TaxNumber, actual.TaxNumber); Assert.Equal(data.DateOfBirth, actual.DateOfBirth); } }
private async Task <Result> ImportPolicy(ScopeOptions scope, ImportClient data, ClientEdit client, Guid userId, List <PolicyType> policyTypes) { var result = new Result(true); if (string.IsNullOrWhiteSpace(data.PolicyNumber)) { return(result); } var policy = await _policyService.GetPolicy(scope, client.Id.Value, data.PolicyCompanyId.Value, data.PolicyNumber); //Policy exits, update if (policy != null) { policy = MapPolicyProperties(policy, data, userId, policyTypes); result = await _policyService.UpdatePolicy(scope, policy); if (!result.Success) { return(result); } } else //else insert { policy = new PolicyEdit() { ClientId = client.Id, CompanyId = data.PolicyCompanyId.Value, Number = data.PolicyNumber }; policy = MapPolicyProperties(policy, data, userId, policyTypes); result = await _policyService.InsertPolicy(scope, policy); if (!result.Success) { return(result); } } return(result); }
public async Task ImportClient_Insert_NoIdButHasPolicyNumber_UnknowClientType() { var options = TestHelper.GetDbContext("ImportClient_Insert_NoIdButHasPolicyNumber_UnknowClientType"); var user1 = TestHelper.InsertUserDetailed(options); var company = TestHelper.InsertCompany(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var policyService = new PolicyService(context, auditService); var contactService = new ContactService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, policyService, contactService, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "", PolicyNumber = "123456798", LastName = "Some Business", PolicyCompanyId = company.Id, PolicyUserFullName = user1.User.FirstName + " " + user1.User.LastName }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(); Assert.Null(actual.IdNumber); Assert.Equal(data.LastName, actual.LastName); Assert.Equal(ClientType.CLIENT_TYPE_UNKNOWN_ENTITY, actual.ClientTypeId); } }
private ClientEdit LoadClientIdNumber(ClientEdit client, ImportClient data) { if (string.IsNullOrWhiteSpace(data.IdNumber)) { return(client); } var id = new IdNumber(data.IdNumber); if (id.IsValid) { client.IdNumber = data.IdNumber; } else { client.AlternateIdNumber = data.IdNumber; } return(client); }
public async Task ImportClient_InsertUnknownEntity() { var options = TestHelper.GetDbContext("ImportClient_InsertUnknownEntity"); var user1 = TestHelper.InsertUserDetailed(options); var clientType = TestHelper.InsertClientTypeUnknown(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, null, lookupService, directoryLookupService); //When var data = new ImportClient() { LastName = "Unknown Here", ClientTypeCode = clientType.Code }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var actual = await context.Client.FirstOrDefaultAsync(); Assert.Null(actual.AlternateIdNumber); Assert.Null(actual.FirstName); Assert.Equal(clientType.Id, actual.ClientTypeId); Assert.Equal(user1.Organisation.Id, actual.OrganisationId); Assert.Equal(data.LastName, actual.LastName); } }
public async Task ImportClient_Insert_WithCellphone() { var options = TestHelper.GetDbContext("ImportClient_Insert_WithCellphone"); var user1 = TestHelper.InsertUserDetailed(options); using (var context = new DataContext(options)) { var auditService = new AuditServiceMock(); var clientService = new ClientService(context, auditService); var contactService = new ContactService(context, auditService); var lookupService = new ClientLookupService(context); var directoryLookupService = new DirectoryLookupService(context); var service = new ClientImportService(context, clientService, null, contactService, lookupService, directoryLookupService); //When var data = new ImportClient() { IdNumber = "8210035032082", Cellphone = "082-572 8997" }; var scope = TestHelper.GetScopeOptions(user1); var result = await service.ImportClient(scope, data); //Then Assert.True(result.Success); var client = await context.Client.FirstOrDefaultAsync(m => m.IdNumber == data.IdNumber); var actual = await context.Contact.SingleOrDefaultAsync(c => c.ClientId == client.Id); Assert.Equal("0825728997", actual.Value); Assert.Equal(ContactType.CONTACT_TYPE_CELLPHONE, actual.ContactTypeId); } }
private ImportResult RunImport(FileInfoSet fileSet, ImportClient client) { Log.Info($"Importing '{fileSet.ConvertedSamplesFile.Name}'..."); var result = GetImportResultWithAction(client, () => client.PostImportForStatusUrl(fileSet.ConvertedSamplesFile)); if (result.HasErrors) { ReportImportFailed(client, result.ResultResponse, fileSet); if (result.SuccessCount > 0 || result.UpdateCount > 0) { Log.Info($"Partial success. '{fileSet.OriginalSondeFile.Name}': " + $"imported {result.SuccessCount}, updated {result.UpdateCount}, failed {result.ErrorCount}."); } return(result); } Log.Info($"'{fileSet.OriginalSondeFile.Name}': " + $"imported {result.SuccessCount}, updated {result.UpdateCount}, failed {result.ErrorCount}."); return(result); }
public ActionResult ImportClient(HttpPostedFileBase file, BALExportClient model, string Command) { DALExportClient dalExportClient = new DALExportClient(); ImportClient importClient = new ImportClient(); try { if (Command == "Export") { if (importClient.ImportExcel(Convert.ToString(model.NotificationFrequencyID), model.NotificationFrequency, model.NotificationTime, Convert.ToString(model.BillingCurrencyID), model.BillingCurrency, Convert.ToString(model.ContractTypeId), model.ContractType, Convert.ToString(model.ClientContactDepartmentId), model.ClientContactDepartment)) { string filepath = Path.Combine(Server.MapPath("~/Upload"), "ClientTemplate.xls"); var fileName = "ClientTemplate.xls"; var mimeType = "application/vnd.ms-excel"; return File(new FileStream(filepath, FileMode.Open), mimeType, fileName); } else { ViewBag.Curry = new SelectList(BAL.CurrencyModel.CurrencyDropDownList(), "Value", "Text"); ViewBag.Notif = new SelectList(BAL.NotificationModel.NotificationDropDownList(1), "Value", "Text"); ViewBag.conType = new SelectList(BAL.ContractModel.ContractDropDownList(), "Value", "Text"); ViewBag.Department = new SelectList(BAL.DepartmentModels.DepartmentDropDownList(), "Value", "Text"); ViewBag.STime = new SelectList(BAL.Common.TimeDropDownList(), "Value", "Text"); } } else if (Command == "Submit") { ViewBag.Isload = true; LoginSession loginsession = (LoginSession)Session["Login"]; string extension = Path.GetExtension(file.FileName); fileName = string.Format(@"{0}." + extension, Guid.NewGuid()); var path = Path.Combine(Server.MapPath("~/ExportFileUpload"), fileName); file.SaveAs(path); //Get Excel Column model.ItemList = dalExportClient.getExcelColumnName(path); //Get DB Table Column model.ListtblColumnName = dalExportClient.GetTableColumnName("SYCOUS.ClientMaster"); Session["DBColumnNameClient"] = model.ListtblColumnName; Session["FilePathClient"] = Path.Combine(Server.MapPath("~/ExportFileUpload"), fileName); ViewBag.Curry = new SelectList(BAL.CurrencyModel.CurrencyDropDownList(), "Value", "Text"); ViewBag.Notif = new SelectList(BAL.NotificationModel.NotificationDropDownList(1), "Value", "Text"); ViewBag.conType = new SelectList(BAL.ContractModel.ContractDropDownList(), "Value", "Text"); ViewBag.Department = new SelectList(BAL.DepartmentModels.DepartmentDropDownList(), "Value", "Text"); ViewBag.STime = new SelectList(BAL.Common.TimeDropDownList(), "Value", "Text"); } } catch (Exception Ex) { ViewBag.Isload = false; ViewBag.Message = Ex.Message; ViewBag.Curry = new SelectList(BAL.CurrencyModel.CurrencyDropDownList(), "Value", "Text"); ViewBag.Notif = new SelectList(BAL.NotificationModel.NotificationDropDownList(1), "Value", "Text"); ViewBag.conType = new SelectList(BAL.ContractModel.ContractDropDownList(), "Value", "Text"); ViewBag.Department = new SelectList(BAL.DepartmentModels.DepartmentDropDownList(), "Value", "Text"); ViewBag.STime = new SelectList(BAL.Common.TimeDropDownList(), "Value", "Text"); } return View(model); }
public async Task <Result> ImportClient(ScopeOptions scope, ImportClient data) { var policyTypes = await _lookupService.GetPolicyTypes(); var clientTypes = await _lookupService.GetClientTypes(); var companies = await _directoryLookupService.GetCompanies(); var validator = new ImportClientValidator(policyTypes, clientTypes, companies); var result = validator.Validate(data).GetResult(); if (!result.Success) { return(result); } //Clean id number data.IdNumber = CleanIdNumber(data.IdNumber); //Load date of birth from IdNumber if possible if (data.DateOfBirth == null) { var id = new IdNumber(data.IdNumber); if (id.IsValid) { data.DateOfBirth = id.DateOfBirth; } } var userId = scope.UserId; //If a user is specified, use it as the scope if (!string.IsNullOrEmpty(data.PolicyUserFullName)) { var parts = data.PolicyUserFullName.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries).ToList(); if (parts.Count < 2) { parts.Add(""); } var userEntityQuery = ScopeQuery.GetUserEntityQuery(_context, scope); var users = await userEntityQuery.ToListAsync(); var userQuery = from entity in users where (String.Equals(entity.FirstName, parts[0], StringComparison.OrdinalIgnoreCase) && String.Equals(entity.LastName, parts[1], StringComparison.OrdinalIgnoreCase)) //JSON Query: should be included in above query || entity.Aliases.Any(alias => String.Equals(alias, data.PolicyUserFullName, StringComparison.OrdinalIgnoreCase)) select entity; var user = userQuery.FirstOrDefault(); if (user == null) { result.AddValidationFailure("UserFullName", "Broker does not exist or is out of scope"); return(result); } userId = user.Id; } //Check if the client exists in the organisation var clients = await FindClient(scope, data); if (clients.Count >= 2) { result.AddValidationFailure("", "There are multiple clients matching this record, please increase specificity"); return(result); } var clientEntity = clients.FirstOrDefault(); ClientEdit client = null; //Client exits, check client is in scope if (clientEntity != null) { client = await _clientService.GetClient(scope, clientEntity.Id); client = LoadClientIdNumber(client, data); client = MapClientProperties(client, data, clientTypes); result = await _clientService.UpdateClient(scope, client); if (!result.Success) { return(result); } } else { client = new ClientEdit(); client = LoadClientIdNumber(client, data); client = MapClientProperties(client, data, clientTypes); client = LoadClientType(client, data); result = await _clientService.InsertClient(scope, client); if (!result.Success) { return(result); } client = (ClientEdit)result.Tag; } result = await ImportEmail(scope, data, client); if (!result.Success) { return(result); } result = await ImportCellphone(scope, data, client); if (!result.Success) { return(result); } result = await ImportPolicy(scope, data, client, userId, policyTypes); return(result); }