Beispiel #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);
        }
Beispiel #2
0
        public async Task <Revenue> UpdateAsync(int revenueId, InsertUpdateRevenueCommand command)
        {
            var revenue = await _revenueRepository.GetAsync(revenueId);

            if (revenue == null)
            {
                throw new EntityNotFoundException("Revenue");
            }

            revenue.AccrualDate     = command.AccrualDate;
            revenue.Amount          = command.Amount;
            revenue.Description     = command.Description;
            revenue.InvoiceId       = command.InvoiceId;
            revenue.TransactionDate = command.TransactionDate;

            await _revenueRepository.SaveChangesAsync();

            return(revenue);
        }
        public async Task <IActionResult> Put(int id, InsertUpdateRevenueCommand command)
        {
            await _revenueService.UpdateAsync(id, command);

            return(NoContent());
        }
        public async Task <ActionResult <CreatedEntityDto> > Post(int customerId, InsertUpdateRevenueCommand command)
        {
            var revenue = await _revenueService.InsertAsync(customerId, command);

            return(new CreatedEntityDto(revenue.Id));
        }