示例#1
0
        public async Task <Revenue> InsertAsync(int customerId, InsertUpdateRevenueCommand command)
        {
            var customer = await _customerRepository.GetAsync(customerId);

            if (customer == null)
            {
                throw new EntityNotFoundException("Customer");
            }

            if (customer.Archived)
            {
                throw new BusinessException($"Customer {customer.CommercialName} is already archived");
            }

            var revenue = new Revenue
            {
                Customer        = customer,
                AccrualDate     = command.AccrualDate,
                Amount          = command.Amount,
                Description     = command.Description,
                InvoiceId       = command.InvoiceId,
                TransactionDate = command.TransactionDate
            };

            _revenueRepository.Add(revenue);
            await _revenueRepository.SaveChangesAsync();

            return(revenue);
        }