Пример #1
0
        public async Task <string> CreateInvoiceNoteOut(InvoiceNoteOutInputModel input)
        {
            var invoice = this.invoiceOuts.All().FirstOrDefault(i => i.Id == input.InvoiceOut.Id);

            if (invoice is null)
            {
                throw new ArgumentNullException();
            }

            var noteInvoice = new InvoiceOut();

            noteInvoice.Number           = input.Number;
            noteInvoice.CreateDate       = input.CreateDate;
            noteInvoice.DueDays          = input.DueDays;
            noteInvoice.BankDetailsId    = input.BankDetailsId;
            noteInvoice.VATReasonId      = input.VATReasonId;
            noteInvoice.NoteInfo         = this.mapper.Map <NoteInfo>(input.Note);
            noteInvoice.NoteInfo.AdminId = invoice.AdminId;
            await this.invoiceOuts.AddAsync(noteInvoice);

            invoice.NoteInvoices.Add(noteInvoice);

            await this.invoiceOuts.SaveChangesAsync();

            return(noteInvoice.Id);
        }
Пример #2
0
        /// <summary>
        /// Updates the invoice out.
        /// </summary>
        /// <param name="invoiceOut">The invoice out.</param>
        /// <returns>The <see cref="Task"/> containing the API response with <see cref="InvoiceOut"/>.</returns>
        public virtual Task <ApiResponse <InvoiceOut> > UpdateAsync(InvoiceOut invoiceOut)
        {
            if (invoiceOut == null)
            {
                throw new ArgumentNullException(nameof(invoiceOut));
            }

            var requestContext = PrepareRequestContext(method: Method.PUT, path: $"{Path}/{invoiceOut.Id}")
                                 .WithBody(Serialize(invoiceOut));

            return(CallAsync <InvoiceOut>(requestContext));
        }
Пример #3
0
        public async Task <string> CreateInvoiceOut(InvoiceOutInputModel input)
        {
            var invoice = this.invoiceOuts.All().FirstOrDefault(i => i.Id == input.InvoiceOut.Id);

            if (invoice is null)
            {
                invoice = new InvoiceOut();

                await this.invoiceOuts.AddAsync(invoice);
            }

            invoice.Number        = input.InvoiceOut.Number;
            invoice.CreateDate    = input.InvoiceOut.CreateDate;
            invoice.DueDays       = input.InvoiceOut.DueDays;
            invoice.BankDetailsId = input.InvoiceOut.BankDetailsId;
            invoice.VATReasonId   = input.InvoiceOut.VATReasonId;
            foreach (var orderToInput in input.OrderTos)
            {
                var orderTo = this.orderTos.All().FirstOrDefault(o => o.Id == orderToInput.Id);
                if (orderTo.InvoiceOut is null)
                {
                    orderTo.InvoiceOut = invoice;
                }
            }

            await this.orderTos.SaveChangesAsync();

            foreach (var orderTo in invoice.OrderTos)
            {
                if (!input.OrderTos.Any(o => o.Id == orderTo.Id))
                {
                    orderTo.InvoiceInId = null;
                }
            }

            this.invoiceOuts.Update(invoice);
            await this.invoiceOuts.SaveChangesAsync();

            return(invoice.Id);
        }