示例#1
0
        public void CounterNextTest()
        {
            var name = Guid.NewGuid().ToString();
            var add  = new CounterAddCommand();

            var result = add.CounterAdd(new CounterAdd()
            {
                Name  = name,
                Value = 1000
            }).Result;

            result.Name.Should().Be(name);
            result.Value.Should().Be(1000);


            var next       = new CounterNextCommand();
            var nextResult = next.CounterNext(new CounterNext()
            {
                Name = name
            }).Result;

            nextResult.Value.Should().Be(1001);

            var find = new GetCounterRequest();

            var result2 = find.GetCounter(new GetCounter()
            {
                Name = result.Name
            }).Result;


            result2.Name.Should().Be(name);
            result2.Value.Should().Be(1001);
        }
        /// <summary> Add a new invoice to the database </summary>
        /// <param name="invoiceAdd">this is a test</param>
        /// <returns></returns>
        /// <remarks>
        /// ///<div class="Section0"><p style="text-align:left;page-break-inside:auto;page-break-after:auto;page-break-before:avoid;margin-top:0pt;margin-bottom:0pt;margin-left:0pt;text-indent:0pt;margin-right:0pt;"><span lang="en-US" style="color:#000000;font-family:Times New Roman;font-size:12pt;text-transform:none;font-weight:normal;font-style:normal;font-variant:normal;">When creating a new invoice first call this command to create an invoice in the system.</span></p>
///<p style="text-align:left;page-break-inside:auto;page-break-after:auto;page-break-before:avoid;line-height:normal;margin-top:0pt;margin-bottom:0pt;margin-left:0pt;text-indent:0pt;margin-right:0pt;"><span style="color:#000000;font-family:Times New Roman;font-size:12pt;text-transform:none;font-weight:normal;font-style:normal;font-variant:normal;">&#xa0;</span></p>
///<p style="text-align:left;page-break-inside:auto;page-break-after:auto;page-break-before:avoid;margin-top:0pt;margin-bottom:0pt;margin-left:0pt;text-indent:0pt;margin-right:0pt;"><span lang="en-US" style="color:#000000;font-family:Times New Roman;font-size:12pt;text-transform:none;font-weight:normal;font-style:normal;font-variant:normal;">Then once the invoice has been created, Invoices Lines can be added to it</span></p>
///</div>

        /// </remarks>
        public async Task <IInvoiceView> InvoiceAdd(IInvoiceAdd invoiceAdd)
        {
            try
            {
                var result = new InvoiceView();
                using (var db = new InvoiceContext())
                {
                    var invoice = new Database.Invoice();
                    if (!db.Customers.Any(w => w.CustomerId == invoiceAdd.CustomerId))
                    {
                        return new InvoiceView()
                               {
                                   __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to find parent for Customer", __CQRSStatusCode = 404
                               }
                    }
                    ;

                    var customer = db.Customers.First(w => w.CustomerId == invoiceAdd.CustomerId);
                    if (customer.Invoices == null)
                    {
                        customer.Invoices = new List <Database.Invoice>();
                    }
                    customer.Invoices.Add(invoice);
                    invoice.CreatedDate        = invoiceAdd.CreatedDate;
                    invoice.DueDate            = invoiceAdd.DueDate;
                    invoice.EmailTo            = invoiceAdd.EmailTo;
                    invoice.OrderedBy          = invoiceAdd.OrderedBy;
                    invoice.PaymentDetails     = invoiceAdd.PaymentDetails;
                    invoice.PurchaseOrderRef   = invoiceAdd.PurchaseOrderRef;
                    invoice.TermsAndConditions = invoiceAdd.TermsAndConditions;
                    //UserCodeBlockStart-PreSave
                    var next       = new CounterNextCommand();
                    var nextResult = await next.CounterNext(new CounterNext()
                    {
                        Name = "Invoice"
                    });

                    invoice.InvoiceNo = nextResult.Value;
                    //UserCodeBlockEnd-PreSave

                    await db.SaveChangesAsync();

                    result.CreatedDate      = invoice.CreatedDate;
                    result.DueDate          = invoice.DueDate;
                    result.EmailTo          = invoice.EmailTo;
                    result.GrandTotal       = invoice.GrandTotal;
                    result.InvoiceEmailed   = invoice.InvoiceEmailed;
                    result.InvoiceId        = invoice.InvoiceId;
                    result.InvoiceNo        = invoice.InvoiceNo;
                    result.OrderedBy        = invoice.OrderedBy;
                    result.PaidAmount       = invoice.PaidAmount;
                    result.PaidDate         = invoice.PaidDate;
                    result.PaidTax          = invoice.PaidTax;
                    result.PaymentDetails   = invoice.PaymentDetails;
                    result.PurchaseOrderRef = invoice.PurchaseOrderRef;
                    result.SubTotal         = invoice.SubTotal;
                    result.Tax = invoice.TaxTotal;
                    result.TermsAndConditions = invoice.TermsAndConditions;
                    return(result);
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLogger().Log(LogLevel.Error, e);
                return(new InvoiceView()
                {
                    __CQRSSuccessful = false, __CQRSErrorMessage = "Unable to create InvoiceView", __CQRSStatusCode = 500
                });
            }
        }