예제 #1
0
        public IActionResult Post([FromBody] PostClientAccountRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ModelState));
            }

            var result = accountServiceRepository.Register(request);

            return(Created("", result));
        }
 public static ClientEntity Parse(PostClientAccountRequest entity)
 {
     if (entity == null)
     {
         return(new ClientEntity());
     }
     return(new ClientEntity()
     {
         Name = entity.Name,
         CPF = entity.CPF
     });
 }
예제 #3
0
 public static AccountEntity Parse(PostClientAccountRequest entity)
 {
     if (entity == null)
     {
         return(new AccountEntity());
     }
     return(new AccountEntity()
     {
         AccountNumber = entity.AccountNumber,
         AgencyNumber = entity.AgencyNumber
     });
 }
예제 #4
0
        public ResultGeneric <PostClientAccountResponse> Register(PostClientAccountRequest entity)
        {
            var accountCreate = new ResultGeneric <PostClientAccountResponse>();

            var newClient  = ClientConverter.Parse(entity);
            var newAccount = AccountConverter.Parse(entity);
            var clientID   = new Guid();

            #region Client
            var client = clientRepository.getByDocument(entity.CPF);
            if (client != null)
            {
                clientID = client.ClientID;
            }
            else
            {
                clientRepository.Insert(newClient);
                clientID = newClient.ClientID;
            }
            #endregion

            #region Account

            if (!accountRepository.AccountExists(entity.AgencyNumber, entity.AccountNumber))
            {
                newAccount.ClientID = clientID;
                accountRepository.Insert(newAccount);

                accountCreate.Success = true;
            }
            else
            {
                accountCreate.Success = false;
                accountCreate.Errors.Add("Conta já existente");
            }

            accountCreate.Data = ClientConverter.Parse(newClient, newAccount);
            #endregion

            return(accountCreate);
        }