示例#1
0
        public async Task <ActionResult <ClubCardUpdateDTO> > UpdateClubCard([FromBody] ClubCardUpdateDTO card, [FromQuery] bool isDeactivating = false)
        {
            try
            {
                var returnedCard = await _cardService.UpdateClubCard(card, isDeactivating);

                return(Ok(returnedCard));
            }
            catch (ArgumentNullException exception)
            {
                return(NotFound(exception.Message));
            }
            catch (Exception exception)
            {
                return(BadRequest(exception.Message));
            }
        }
示例#2
0
        public async Task <ClubCardUpdateDTO> UpdateClubCard(ClubCardUpdateDTO card, bool isDeactivating)
        {
            var mappedCard = _mapper.Map <ClubCard>(card);

            if (!isDeactivating)
            {
                if (!card.UnlimitedValidityPeriod)
                {
                    mappedCard.ExpirationDate = mappedCard.PurchaseDate.AddDays(card.ValidityPeriod);
                }
            }
            else
            {
                mappedCard.ExpirationDate = DateTime.Now;
            }
            var returnedCard = await _cardRepository.UpdateClubCard(mappedCard);

            return(_mapper.Map <ClubCardUpdateDTO>(returnedCard));
        }