private string GetOpenAccountSignature(RequestActionDto action) { var data = new { action.Timestamp, action.ActionType, EmployeeId = action.Employee.Id, CreditRequestId = action.CreditRequest.Id, Duration = action.CreditRequest.MonthDuration, Sum = action.CreditRequest.CreditSum.Value, SumCurrencyId = action.CreditRequest.CreditSum.Currency.Id, CreditTypeId = action.CreditRequest.CreditType.Id }; var json = JsonConvert.SerializeObject(data); return(_signatureService.Sign(json, action.Employee.User.Key).Value); }
public async Task <CommandResult> OpenCreditAccountAsync(OpenCreditAccountCommand command) { var rightsRes = await CheckEmployeeRightsAsync(command.EmployeeId, EmployeeRights.Operator); var employeeRes = await GetEmployeeAsync(command.EmployeeId); var requestRes = await GetCreditRequestAsync(command.CreditRequestId); var res = CheckQueries(rightsRes, employeeRes, requestRes); if (res.IsFailed) { return(new CommandResult(command, false).From(res)); } var accountRes = await _creditAccountService.OpenCreditAccountAsync(new OpenAccountCommand { Request = requestRes.Value }); if (accountRes.IsFailed) { return(new CommandResult(command, false).From(accountRes)); } var request = requestRes.Value; request.IsOpen = true; request.RequestOpener = employeeRes.Value; var updateRes = await _creditRequestService.UpdateModelAsync(request); if (updateRes.IsFailed) { return(new CommandResult(command, false).From(updateRes)); } var action = new RequestActionDto { Timestamp = DateTime.Now, Employee = employeeRes.Value, CreditRequest = request, ActionType = GetActionType(command.GetType().Name) }; action.Signature = GetOpenAccountSignature(action); await _requestActionService.CreateModelAsync(action); return(new CommandResult(command, true)); }
private async Task <CommandResult> SignApproveAsync(ApproveCommand command, CreditRequestDto request) { var employeeRes = await GetEmployeeAsync(command.EmployeeId); if (employeeRes.IsFailed) { return(new CommandResult(command, false).From(employeeRes)); } if (employeeRes.Value == null || request == null) { return(new CommandResult(command, false).Error("Invalid command")); } var action = new RequestActionDto { Timestamp = DateTime.Now, Employee = employeeRes.Value, CreditRequest = request, ActionType = GetActionType(command.GetType().Name) }; action.Signature = GetApproveSignature(action, command); return(await _requestActionService.CreateModelAsync(action)); }