Ejemplo n.º 1
0
        public async Task <DataHolder <CreditCard> > ChangeCreditLimitAsync(ChangeCreditLimitDto limitDto, Guid userId)
        {
            if (!limitDto.Id.HasValue)
            {
                return(DataHolder <CreditCard> .CreateFailure("Invalid credit card Id"));
            }

            var creditCard = await GetCreditCardById(limitDto.Id.Value, userId);

            if (creditCard == null)
            {
                return(DataHolder <CreditCard> .CreateFailure("Credit card doesn't exist"));
            }

            creditCard.CreditLimit = limitDto.NewLimit;

            var updateResult = await _creditCardRepository.UpdateAsync(creditCard);

            if (updateResult < 0)
            {
                return(DataHolder <CreditCard> .CreateFailure("Can't update credit card"));
            }

            return(DataHolder <CreditCard> .CreateSuccess(creditCard));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> ChangeCreditLimit([FromBody] ChangeCreditLimitDto creditLimitDto)
        {
            var userIdHolder = await _userService.GetUserId(User.Identity.Name);

            if (userIdHolder.Status == DataHolderStatus.Unauthorized)
            {
                return(Unauthorized());
            }

            var cardHolder = await _creditCardService.ChangeCreditLimitAsync(creditLimitDto, new Guid(userIdHolder.Data));

            if (cardHolder.Status == DataHolderStatus.Failure)
            {
                return(BadRequest(cardHolder.Message));
            }

            return(Ok(_mapper.Map <CreditCard, CreditCardDto>(cardHolder.Data)));
        }