Ejemplo n.º 1
0
        public CommandResult OpenCreditAccount(OpenCreditAccountCommand command)
        {
            var rightsRes   = CheckEmployeeRights(command.EmployeeId, EmployeeRights.Operator);
            var employeeRes = GetEmployee(command.EmployeeId);
            var requestRes  = GetCreditRequest(command.CreditRequestId);
            var res         = CheckQueries(rightsRes, employeeRes, requestRes);

            if (res.IsFailed)
            {
                return(new CommandResult(command, false).From(res));
            }
            var accountRes = _creditAccountService.OpenCreditAccount(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 = _creditRequestService.UpdateModel(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);
            _requestActionService.CreateModel(action);
            return(new CommandResult(command, true));
        }