Exemplo n.º 1
0
        public async Task <InvoiceSupplement> UpdateAsync(InvoiceSupplement invoiceSupplement)
        {
            var query = new QuerySet();

            query.Include.Fields = new string[] { "invoice" };
            var existingInvoiceSupplement = await _invoiceSupplementDataProvider.GetByIdAsync(invoiceSupplement.Id, query);

            if (invoiceSupplement.Id != existingInvoiceSupplement.Id)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice-supplement id cannot be updated.");
            }
            if (invoiceSupplement.SequenceNumber != existingInvoiceSupplement.SequenceNumber)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice-supplement sequence-number cannot be updated.");
            }

            await EmbedRelationsAsync(invoiceSupplement, existingInvoiceSupplement);

            if (invoiceSupplement.Invoice == null)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice is required.");
            }

            invoiceSupplement = await _invoiceSupplementDataProvider.UpdateAsync(invoiceSupplement);

            await _invoiceDataProvider.SyncAmountAndVatAsync(invoiceSupplement.Invoice.Id);

            return(invoiceSupplement);
        }
Exemplo n.º 2
0
        public async Task <InvoiceSupplement> CreateAsync(InvoiceSupplement invoiceSupplement)
        {
            var invoiceSupplementRecord = _mapper.Map <DataProvider.Models.InvoiceSupplement>(invoiceSupplement);

            invoiceSupplementRecord.Currency       = "EUR";
            invoiceSupplementRecord.SequenceNumber = 0;

            _context.InvoiceSupplements.Add(invoiceSupplementRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <InvoiceSupplement>(invoiceSupplementRecord));
        }
Exemplo n.º 3
0
        public IEnumerable <IResource> CollectIncluded(InvoiceSupplement invoiceSupplement, IncludeQuery includeQuery)
        {
            ISet <IResource> included = new HashSet <IResource>();

            // one-relations
            if (includeQuery.Contains("invoice") && invoiceSupplement.Invoice != null)
            {
                included.Add(_mapper.Map <InvoiceDto>(invoiceSupplement.Invoice));
            }

            return(included);
        }
Exemplo n.º 4
0
        public async Task <InvoiceSupplement> UpdateAsync(InvoiceSupplement invoiceSupplement)
        {
            var invoiceSupplementRecord = await FindByIdAsync(invoiceSupplement.Id);

            _mapper.Map(invoiceSupplement, invoiceSupplementRecord);

            invoiceSupplementRecord.Currency       = "EUR";
            invoiceSupplementRecord.SequenceNumber = 0;

            _context.InvoiceSupplements.Update(invoiceSupplementRecord);
            await _context.SaveChangesAsync();

            return(_mapper.Map <InvoiceSupplement>(invoiceSupplementRecord));
        }
Exemplo n.º 5
0
 // Embed relations in invoice supplement resource: reuse old relation if there is one and it hasn't changed
 private async Task EmbedRelationsAsync(InvoiceSupplement invoiceSupplement, InvoiceSupplement oldInvoiceSupplement = null)
 {
     try {
         if (oldInvoiceSupplement != null && oldInvoiceSupplement.Invoice != null)
         {
             invoiceSupplement.Invoice = oldInvoiceSupplement.Invoice; // frontend doesn't always include the invoice in PATCH requests
         }
         else
         {
             invoiceSupplement.Invoice = await _invoiceDataProvider.GetByIdAsync(invoiceSupplement.Invoice.Id);
         }
     }
     catch (EntityNotFoundException)
     {
         _logger.LogDebug($"Failed to find a related entity");
         throw new IllegalArgumentException("IllegalAttribute", "Not all related entities exist.");
     }
 }
Exemplo n.º 6
0
        public async Task <InvoiceSupplement> CreateAsync(InvoiceSupplement invoiceSupplement)
        {
            if (invoiceSupplement.Id != 0)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice-supplement cannot have an id on create.");
            }
            if (invoiceSupplement.SequenceNumber != 0)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice-supplement cannot have a sequence-number on create.");
            }
            if (invoiceSupplement.Invoice == null)
            {
                throw new IllegalArgumentException("IllegalAttribute", "Invoice is required on invoice supplement creation.");
            }

            await EmbedRelationsAsync(invoiceSupplement);

            invoiceSupplement = await _invoiceSupplementDataProvider.CreateAsync(invoiceSupplement);

            await _invoiceDataProvider.SyncAmountAndVatAsync(invoiceSupplement.Invoice.Id);

            return(invoiceSupplement);
        }
Exemplo n.º 7
0
        InvoiceSupplementRelationshipsDto ITypeConverter <InvoiceSupplement, InvoiceSupplementRelationshipsDto> .Convert(InvoiceSupplement source, InvoiceSupplementRelationshipsDto destination, ResolutionContext context)
        {
            var relationships = new InvoiceSupplementRelationshipsDto();

            relationships.Invoice = GetOneRelationship <Invoice>("invoice-supplements", source.Id, "invoice", source.Invoice, context);
            return(relationships);
        }