public async Task <SaveResponse <IList <IDocumentHistory> > > SaveAllDocumentHistoryAsync(IList <IDocumentHistory> items) { var response = new SaveResponse <IList <IDocumentHistory> >(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetDocumentHistoryMergeStatement(); var dtos = items.Select(i => { var dto = new DocumentHistoryDto(); return(dto.FromModel(i)); }).ToList(); var trans = connection.BeginTransaction(); var result = await connection.ExecuteAsync(sql, dtos, trans); trans.Commit(); response.Content = items; response.Message = $@"Document history was inserted/updated successfully."; } } catch (Exception e) { var message = $@"Error saving document history."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task<SaveResponse> SaveSessionStateAsync(IUser user) { var response = new SaveResponse(); try { const string sql = @"UPDATE [Identity].[User] SET [LastAccessedDate] = SYSDATETIMEOFFSET() WHERE [Id] = @id; INSERT INTO [Identity].[UserSession](UserId, LoginDate) VALUES(@id, SYSDATETIMEOFFSET());"; var parms = new { id = user.Id }; using (var connection = ConnectionFactory.GetConnection()) { var x = await connection.ExecuteAsync(sql, parms); } } catch (Exception e) { Console.WriteLine(e); response.AddError(e); LogManager.LogError(e, $@"Error saving login state for user: {user.Email}."); } return response; }
public async Task <SaveResponse> SaveAsync(IUser user) { var response = new SaveResponse(); try { var validateResponse = await _userValidator.ValidateAsync(user); if (validateResponse.IsValid) { response = await _userRepository.SaveAsync(user); } else { response.AddErrors(validateResponse.Errors); } } catch (Exception e) { response.AddError(e); Console.WriteLine(e); } return(response); }
public virtual async Task <SaveResponse <TModel> > SaveAsync(TModel item) { var response = new SaveResponse <TModel>(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetMergeStatement(); var results = await connection.QuerySingleAsync <TDto>(sql, Dto.FromModel(item)); response.Content = results.ToModel(); response.Message = $@"{results} {typeof(TModel).Name} record was inserted/updated."; } } catch (Exception e) { var message = $@"Error saving {typeof(TModel).Name} information."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse <IReadOnlyList <ISalesVerification> > > SaveAllSalesVerificationAsync(List <ISalesVerification> items) { var response = new SaveResponse <IReadOnlyList <ISalesVerification> >(); try { if (items.Any()) { var dto = new SalesVerificationDto(); using (var connection = ConnectionFactory.GetConnection()) { var sql = "spmSalesVerification"; var results = await connection.ExecuteAsync(sql, items.Select(m => dto.FromModel(m)), commandType : CommandType.StoredProcedure); response.Content = items; response.Message = $@"Sales verification records were inserted/updated."; } } } catch (Exception e) { var message = $@"Error saving Sales information."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse <IReadOnlyList <ISalesVerification> > > SaveAllSalesVerficationAsync(List <ISalesVerification> salesVerifications) { var saveResponse = new SaveResponse <IReadOnlyList <ISalesVerification> >(); try { // Save verification files var filesToSave = salesVerifications .Where(s => s.VerificationFile != null) .Select(s => s.VerificationFile) .ToList(); var uploadSaveResponse = await _fileUploadApplicationService.SaveAllAsync(filesToSave); if (uploadSaveResponse.IsSuccessful) { foreach (var file in uploadSaveResponse.Content) { var sale = salesVerifications.First(s => s.VerificationFile.OriginalFileName == file.OriginalFileName) .VerificationFile = file; } } saveResponse = await _salesRepository.SaveAllSalesVerificationAsync(salesVerifications); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving saless"); } return(saveResponse); }
public async Task <SaveResponse <IContact> > SaveAsync(IContact model) { var saveResponse = new SaveResponse <IContact>(); try { // Make sure contact is valid before saving var validationResult = await _contactValidator.ValidateAsync(model); if (validationResult.IsValid) { saveResponse = await _contactRepository.SaveAsync(model); } else { saveResponse.AddErrors(validationResult.Errors); saveResponse.Message = string.Join <ValidationFailure>(". \n", validationResult.Errors.ToArray()); } } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving contact"); } return(saveResponse); }
public async Task <SaveResponse <IReadOnlyList <IPayrollClassification> > > SaveAllPayrollClassification(IReadOnlyList <IPayrollClassification> items) { var response = new SaveResponse <IReadOnlyList <IPayrollClassification> >(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetPayrollClassificationUpdateSqlStatement(); var results = await connection.ExecuteAsync(sql, items.Select(m => { var dto = new PayrollClassificationDto(); return(dto.FromModel(m)); })); response.Content = items; response.Message = $@"{results} payroll classification record were inserted/updated."; } } catch (Exception ex) { var messaage = $@"Unable to save payroll classification records."; response.AddError(ex); LogManager.LogError(ex, messaage); Console.WriteLine(ex); } return(response); }
public async Task <SaveResponse <ILabor> > SaveAsync(ILabor labor) { var saveResponse = new SaveResponse <ILabor>(); try { saveResponse = await _laborRepository.SaveAsync(labor); if (saveResponse.IsSuccessful) { // Save certificate of insurance var savedLabor = saveResponse.Content; if (labor.CertificateOfInsurance != null) { savedLabor.CertificateOfInsurance = labor.CertificateOfInsurance; var certificateResponse = await _certificateOfInsuranceApplicationService.SaveAsync(savedLabor.CertificateOfInsurance); if (certificateResponse.IsSuccessful) { savedLabor.CertificateOfInsurance = certificateResponse.Content; } } } } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving labor"); } return(saveResponse); }
public async Task <SaveResponse <IDocumentHistory> > SaveDocumentHistoryAsync(IDocumentHistory item) { var response = new SaveResponse <IDocumentHistory>(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetDocumentHistoryMergeStatement(); var dto = new DocumentHistoryDto(); var result = await connection.QuerySingleAsync <DocumentHistoryDto>(sql, dto.FromModel(item)); response.Content = result.ToModel(); response.Message = $@"Document history was inserted/updated successfully."; } } catch (Exception e) { var message = $@"Error saving document history."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse> RegisterUserAsync(RegisterRequest request) { var response = new SaveResponse(); try { // 1. check if valid policy number and pin. var validResponse = await _policyAgentService.IsValidPolicyAuditAsync(request.Identity.Pin, request.Identity.PolicyNumber); if (validResponse.IsSuccessful && validResponse.Content) { // 2. Save user var userResponse = await _userRepository.SaveAsync(request.Identity); response.Join <SaveResponse>(userResponse); if (userResponse.IsSuccessful) { // 3. Create and save the agent var agent = _policyAgentService.CreateAgent(userResponse.Content); agent.PolicyNumber = request.Identity.PolicyNumber; response = await _policyAgentService.SaveAgentInformationAsync(agent); } else { response.AddError($@"Unable to register user for Pin: {request.Identity.PolicyNumber}, Policy Number: { request.Identity.Pin }. The Pin/Policy Number does not match our records."); } } } catch (Exception e) { Console.WriteLine(e); response.AddError(e); } return(response); }
public override async Task <SaveResponse <IRuleSet> > SaveAsync(IRuleSet item) { var response = new SaveResponse <IRuleSet>(); try { var sql = GetMergeStatement(); using (var connection = ConnectionFactory.GetConnection()) { using (var trans = connection.BeginTransaction()) { // Save rule set var ruleSetDto = await connection.QuerySingleAsync <RuleSetDto>(sql, Dto.FromModel(item), trans); // Save rules var ruleDtos = item.Rules .Select(r => { var dto = (RuleDto) new RuleDto() .FromModel(r); dto.RuleSetId = ruleSetDto.Id; return(dto); }); await connection.ExecuteAsync(GetRuleMergeStatement(), ruleDtos, trans); trans.Commit(); sql = $@"{GetRuleSelectStatement()} AND RuleSetId = @ruleSetId;"; var results = await connection.QueryAsync <RuleDto>(sql, new { RuleSetId = ruleSetDto.Id }); var ruleSet = ruleSetDto.ToModel(); ruleSet.Rules = results .Select(dto => dto.ToModel()) .AsList(); response.Content = ruleSet; response.Message = $@"RuleSet: {item.Name} record was inserted/updated."; } } } catch (Exception e) { var message = $@"Error saving RuleSet information."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public override async Task <SaveResponse <IDocument> > SaveAsync(IDocument item) { var response = new SaveResponse <IDocument>(); try { using (var connection = ConnectionFactory.GetConnection()) { var trans = connection.BeginTransaction(); var sql = GetDocumentMergeStatement(); var mergeDocumentDto = await connection.QuerySingleAsync <DocumentDto>(sql, Dto.FromModel(item), trans); var document = mergeDocumentDto.ToModel(); var fieldDtos = item.Fields.Select(f => { var fieldDto = new MergeDocumentFieldDto { DocumentId = document.Id }; return((MergeDocumentFieldDto)fieldDto.FromModel(f)); }).AsList(); foreach (var fieldDto in fieldDtos) { document.Fields.Add( connection.QuerySingle <MergeDocumentFieldDto>(GetFieldMergeStatement(), fieldDto, trans).ToModel()); } trans.Commit(); document.Fields = fieldDtos .Select(dto => dto.ToModel()) .AsList(); response.Content = document; response.Message = $@"Merge document {document.Name} was inserted/updated successfully."; } } catch (Exception e) { var message = $@"Error saving merge document."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public override async Task <SaveResponse <IAuditWorkflow> > SaveAsync(IAuditWorkflow item) { var response = new SaveResponse <IAuditWorkflow>(); try { var sql = GetMergeStatement(); using (var connection = ConnectionFactory.GetConnection()) { using (var trans = connection.BeginTransaction()) { // Save workflow var workflowDto = await connection.QuerySingleAsync <WorkflowDto>(sql, Dto.FromModel(item), trans); // Save workflow steps var workflowStepDtos = item.Steps.Values .Select(r => { var dto = (WorkflowStepDto) new WorkflowStepDto() .FromModel(r); dto.WorkflowId = workflowDto.Id; return(dto); }); await connection.ExecuteAsync(GetWorkflowStepMergeStatement(), workflowStepDtos, trans); trans.Commit(); // Get the workflow now that the IDs have been created var getResponse = await GetByIdAsync(workflowDto.Id); response.Join <SaveResponse <IAuditWorkflow> >(getResponse); response.Content = getResponse.Content; response.Message = $@"RuleSet: {item.Name} record was inserted/updated."; } } } catch (Exception e) { var message = $@"Error saving RuleSet information."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse <IList <IDocumentHistory> > > SaveAllDocumentHistoryAsync(IList <IDocumentHistory> items) { var response = new SaveResponse <IList <IDocumentHistory> >(); try { response = await _documentRepository.SaveAllDocumentHistoryAsync(items); } catch (Exception e) { _logManager.LogError(e, "DocumentApplicationService.GetFieldValuesAsync"); response.AddError(e); } return(response); }
public async Task <SaveResponse> SaveSessionStateAsync(IUser user) { var response = new SaveResponse(); try { response = await _userRepository.SaveSessionStateAsync(user); } catch (Exception e) { response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse> UpdateAuditStatus(int auditId, AuditStatuses status, int userId) { var response = new SaveResponse(); try { response = await _auditRepository.UpdateAuditStatus(auditId, status, userId); } catch (Exception ex) { Console.WriteLine(ex); response.AddError(ex); _logManager.LogError(ex, "Error updating audit status"); } return(response); }
public async Task <SaveResponse> NotifyPolicyHolder(int auditId, int notificationType, DateTime sentDate) { var response = new SaveResponse(); try { response = await _auditRepository.NotifyPolicyHolder(auditId, notificationType, sentDate); } catch (Exception ex) { Console.WriteLine(ex); response.AddError(ex); _logManager.LogError(ex, "Error updating audit status"); } return(response); }
public async Task <SaveResponse <IReadOnlyList <IAuditUpload> > > SaveAllAsync(IReadOnlyList <IAuditUpload> auditUploads) { var saveResponse = new SaveResponse <IReadOnlyList <IAuditUpload> >(); try { saveResponse = await _auditUploadRepository.SaveAllAsync(auditUploads); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving auditUploads"); } return(saveResponse); }
public async Task <SaveResponse <IWpdConfig> > SaveAsync(IWpdConfig wpdConfig) { var saveResponse = new SaveResponse <IWpdConfig>(); try { saveResponse = await _wpdConfigRepository.SaveAsync(wpdConfig); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving wpdConfig"); } return(saveResponse); }
public async Task <SaveResponse <IReadOnlyList <ISales> > > SaveAllSalesAsync(IReadOnlyList <ISales> sales) { var saveResponse = new SaveResponse <IReadOnlyList <ISales> >(); try { saveResponse = await _salesRepository.SaveAllSalesAsync(sales); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving saless"); } return(saveResponse); }
public async Task <SaveResponse <IRemunerationSales> > SaveAsync(IRemunerationSales remunerationSales) { var saveResponse = new SaveResponse <IRemunerationSales>(); try { saveResponse = await _remunerationSalesRepository.SaveAsync(remunerationSales); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving remunerationSales"); } return(saveResponse); }
public async Task <SaveResponse <IRuleGrammarTerminal> > SaveAsync(IRuleGrammarTerminal ruleGrammarTerminal) { var saveResponse = new SaveResponse <IRuleGrammarTerminal>(); try { saveResponse = await _ruleGrammarTerminalRepository.SaveAsync(ruleGrammarTerminal); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving ruleGrammarTerminal"); } return(saveResponse); }
public async Task <SaveResponse <IActivityNote> > SaveAsync(IActivityNote activityNote) { var saveResponse = new SaveResponse <IActivityNote>(); try { saveResponse = await _activityNoteRepository.SaveAsync(activityNote); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving activityNote"); } return(saveResponse); }
public async Task <SaveResponse <IClientSetting> > SaveAsync(IClientSetting clientSetting) { var saveResponse = new SaveResponse <IClientSetting>(); try { saveResponse = await _clientSettingRepository.SaveAsync(clientSetting); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving clientSetting"); } return(saveResponse); }
public async Task <SaveResponse> SaveAgentInformationAsync(PolicyAgent agent) { var response = new SaveResponse(); try { response = await _policyRepository.SaveAgentAsync(agent); } catch (Exception e) { Console.WriteLine(e); response.AddError(e); } return(response); }
public async Task <SaveResponse <IReadOnlyList <IClassCode> > > SaveAllAsync(IReadOnlyList <IClassCode> classCodes) { var saveResponse = new SaveResponse <IReadOnlyList <IClassCode> >(); try { saveResponse = await _classCodeRepository.SaveAllAsync(classCodes); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving classCodes"); } return(saveResponse); }
public async Task <SaveResponse <IReadOnlyList <IPayrollLimit> > > SaveAllAsync(IReadOnlyList <IPayrollLimit> payrollLimits) { var saveResponse = new SaveResponse <IReadOnlyList <IPayrollLimit> >(); try { saveResponse = await _payrollLimitRepository.SaveAllAsync(payrollLimits); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving payrollLimits"); } return(saveResponse); }
public async Task <SaveResponse <IAuditEvent> > SaveAsync(IAuditEvent auditEvent) { var saveResponse = new SaveResponse <IAuditEvent>(); try { saveResponse = await _auditEventRepository.SaveAsync(auditEvent); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving auditEvent"); } return(saveResponse); }
public async Task <SaveResponse <IPolicy> > SaveAsync(IPolicy policy) { var saveResponse = new SaveResponse <IPolicy>(); try { saveResponse = await _policyRepository.SaveAsync(policy); } catch (Exception ex) { Console.WriteLine(ex); saveResponse.AddError(ex); _logManager.LogError(ex, "Error saving policy"); } return(saveResponse); }