示例#1
0
        public object Delete(CreditCardRequest request)
        {
            var session   = this.GetSession();
            var accountId = new Guid(session.UserAuthId);

            var activeOrder = _orderDao.GetOrdersInProgressByAccountId(accountId);

            if (activeOrder.Any())
            {
                throw new HttpError("Can't delete credit card when an order is in progress");
            }

            var creditCards = _dao.FindByAccountId(accountId);

            var creditCardDetails = creditCards.FirstOrDefault(x => x.CreditCardId == request.CreditCardId);

            if (creditCardDetails == null)
            {
                return(new HttpError("Cannot find the credit card"));
            }

            var defaultCreditCard = creditCards.FirstOrDefault(x => x.CreditCardId != request.CreditCardId);
            var command           = new DeleteAccountCreditCard
            {
                AccountId               = accountId,
                CreditCardId            = request.CreditCardId,
                NextDefaultCreditCardId = defaultCreditCard != null ? defaultCreditCard.CreditCardId : (Guid?)null,
            };

            _commandBus.Send(command);

            return(defaultCreditCard);
        }
示例#2
0
        public void Handle(DeleteAccountCreditCard command)
        {
            var account = _repository.Find(command.AccountId);

            account.RemoveCreditCard(command.CreditCardId, command.NextDefaultCreditCardId);
            _repository.Save(account, command.Id.ToString());
        }