Ejemplo n.º 1
0
        public async Task <ActionResult> GetPocketStatus(string accountNumber, [FromQuery] GetPocketStatusDTO request)
        {
            if (string.IsNullOrEmpty(accountNumber) ||
                accountNumber != request.MasterAccount)
            {
                ModelState.AddModelError("", AccountNotFoundException.DefaultErrorMessage);
                return(BadRequest(ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var resultDTO = await PocketService.GetPocketStatusAsync(request);

                return(new JsonResult(resultDTO));
            }
            catch (Exception ex)
            {
                return(HandleException(ex));
            }
        }
Ejemplo n.º 2
0
        public async Task <StatusResultDTO> GetPocketStatusAsync(GetPocketStatusDTO request)
        {
            var holder = await DbContext
                         .Holders
                         .SingleOrDefaultAsync(h => h.MasterAccount == request.MasterAccount && h.PINCode == request.PinCode);

            if (holder == null)
            {
                throw new AccountNotFoundException();
            }

            await DbContext.Entry(holder).Collection(h => h.Accounts).LoadAsync();

            return(new StatusResultDTO
            {
                Deposits = holder.Accounts.Select(a =>
                                                  new DepositItemDTO
                {
                    AccountNumber = a.Number,
                    Currency = a.Currency,
                    Sum = a.Debit
                })
            });
        }