public async Task <(bool Success, string Error, CreateClientIdentificationViewModel Model)> FetchCreateClientIdentificationViewModelForEditAsync(int id) { var success = false; var error = ""; var model = new CreateClientIdentificationViewModel(); try { if (id > 0) { var identification = await _clientIdentificationRepository.FetchBaseByIdAsync(id); if (identification != null) { model.ClientId = identification.ClientId; model.ClientIdentificationId = identification.ClientIdentificationId; model.IdentificationDocumentId = identification.IdentificationDocumentId; model.IdentificationDocumentNumber = Encryption.Decrypt(identification.IdentificationDocumentNumberEncrypted, identification.IdentificaitonDocumentNumberUniqueKey); success = true; } else { error = "Unable to locate data"; } } else { error = "Invalid request"; } } catch (Exception ex) { error = "Somethong went wrong while processing your request."; _logger.LogError("ClientIdentificationService.FetchCreateClientIdentificationViewModelForEditAsync - exception:{@Ex}", args: new object[] { ex }); } return(Success : success, Error : error, Model : model); }
public async Task <IActionResult> SaveClientIdentification(CreateClientIdentificationViewModel model) { _logger.LogInformation(GetLogDetails() + " - model:{@Model}", new object[] { model }); if (ModelState.IsValid) { var userId = _userManager.GetUserId(User); var result = await _clientIdentificationService.SaveClientIdentificationAsync(model, userId); return(Json(new { success = result.Success, error = result.Error })); } else { return(Json(new { success = false, error = "Invalid Request" })); } }
public async Task <(bool Success, string Error)> SaveClientIdentificationAsync(CreateClientIdentificationViewModel model, string userId) { var success = false; var error = ""; try { ClientIdentification id = null; if (model.ClientIdentificationId > 0) { id = await _clientIdentificationRepository.FetchBaseByIdAsync(model.ClientIdentificationId); } if (id == null) { id = new ClientIdentification { CreatedUtc = DateTime.UtcNow, CreatedUserId = userId }; } else { id.AuditUserId = userId; id.AuditUtc = DateTime.UtcNow; } // save other values id.ClientId = model.ClientId; id.IdentificationDocumentId = model.IdentificationDocumentId; // encrypt id info var idNumberEncryptionResult = Encryption.Encrypt(model.IdentificationDocumentNumber); id.IdentificationDocumentNumberEncrypted = idNumberEncryptionResult.EncryptedString; id.IdentificaitonDocumentNumberUniqueKey = idNumberEncryptionResult.UniqueKey; await _clientIdentificationRepository.SaveClientIdentificationAsync(id); success = true; } catch (Exception ex) { error = "Unexpected error occurred while processing your request."; _logger.LogError("ClientIdentificationService.SaveClientIdentificationAsync - exception:{@Ex}", new object[] { ex }); } return(success, error); }