示例#1
0
        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));
        }