예제 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("InvoiceNumber,CreatedOn,DebtorID,ExpirationDate,Type")] Invoice invoice, string pids, string amounts, string total)
        {
            if (id != invoice.InvoiceNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                Invoice invoiceBeforeUpdate = _context.Invoices.Single(s => s.InvoiceNumber == invoice.InvoiceNumber);
                await UpdateInvoice(invoice, pids, amounts, total);

                //SEND MAIL TO DEBTOR NOTIFYING ABOUT INVOICE
                if (invoice.Type == "Final" && invoiceBeforeUpdate.Type != "Final")
                {
                    Debtor            debtor = _context.Debtors.Single(s => s.DebtorID == invoice.DebtorID);
                    AuthMessageSender email  = new AuthMessageSender();
                    await email.SendInvoiceEmailAsync(debtor.Email);
                }

                return(RedirectToAction("Index"));
            }

            ViewData["DebtorID"] = new SelectList(_context.Debtors, "DebtorID", "FullName", invoice.DebtorID);
            return(View(invoice));
        }
예제 #2
0
        public async Task <IActionResult> Create([Bind("InvoiceNumber,CreatedOn,DebtorID,ExpirationDate,Type")] Invoice invoice, string total, string pids, string amounts)
        {
            if (ModelState.IsValid)
            {
                await CreateInvoice(invoice, pids, amounts, total);

                //SEND MAIL TO DEBTOR NOTIFYING ABOUT INVOICE
                if (invoice.Type == "Final")
                {
                    Debtor            debtor = _context.Debtors.Single(s => s.DebtorID == invoice.DebtorID);
                    AuthMessageSender email  = new AuthMessageSender();
                    await email.SendInvoiceEmailAsync(debtor.Email);
                }

                return(RedirectToAction("Index"));
            }

            var products = _context.Products
                           .Select(s => new SelectListItem
            {
                Value = s.ProductID.ToString() + "_" + s.Price.ToString(),
                Text  = s.Name
            });

            ViewBag.Products     = new SelectList(products, "Value", "Text", pids);
            ViewData["DebtorID"] = new SelectList(_context.Debtors, "DebtorID", "FullName", invoice.DebtorID);
            return(View(invoice));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id,
                                               [Bind("InvoiceNumber,CreatedOn,DebtorID,CompanyID,Paid,ExpirationDate,Type,Discount,Comments")] Invoice invoice,
                                               string pids, string amounts, string total)
        {
            if (id != invoice.InvoiceNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                //Update invoice
                Invoice invoiceBeforeUpdate = _context.Invoices.Single(s => s.InvoiceNumber == invoice.InvoiceNumber);
                await UpdateInvoice(invoice, pids, amounts, total);

                //Send email to debtor about new invoice
                if (invoice.Type == "Final" && invoiceBeforeUpdate.Type != "Final" && !String.IsNullOrEmpty(invoice.DebtorID.ToString()))
                {
                    Debtor            debtor = _context.Debtors.Single(s => s.DebtorID == invoice.DebtorID);
                    AuthMessageSender email  = new AuthMessageSender(_settings);
                    await email.SendInvoiceEmailAsync(debtor.Email);
                }
                else if (invoice.Type == "Final" && invoiceBeforeUpdate.Type != "Final" && String.IsNullOrEmpty(invoice.CompanyID.ToString()))
                {
                    Company           company = _context.Companies.Single(s => s.CompanyID == invoice.CompanyID);
                    AuthMessageSender email   = new AuthMessageSender(_settings);
                    await email.SendInvoiceEmailAsync(company.Email);
                }

                return(RedirectToAction("Index"));
            }

            //Create selectlist with all companies
            var companies = _context.Companies
                            .Select(s => new SelectListItem {
                Value = s.CompanyID.ToString(),
                Text  = s.CompanyName.ToString() + " in " + s.City.ToString()
            });

            //Viewbags and viewdata
            ViewData["CompanyID"] = new SelectList(companies, "Value", "Text", invoice.CompanyID);
            ViewData["DebtorID"]  = new SelectList(_context.Debtors, "DebtorID", "FullName", invoice.DebtorID);

            return(View(invoice));
        }
예제 #4
0
        public async Task <IActionResult> Create(
            [Bind("InvoiceNumber,CreatedOn,DebtorID,CompanyID,Paid,ExpirationDate,Type,Discount,Comments")] Invoice invoice,
            string total, string pids, string amounts)
        {
            if (ModelState.IsValid)
            {
                //Check if debtor or company id is null
                if (invoice.DebtorID is int)
                {
                    invoice.CompanyID = null;
                }
                else if (invoice.CompanyID is int)
                {
                    invoice.DebtorID = null;
                }

                //Add invoice to database
                await CreateInvoice(invoice, pids, amounts, total);

                //Send email to debtor about new invoice
                if (invoice.Type == "Final")
                {
                    if (invoice.DebtorID is int)
                    {
                        Debtor            debtor = _context.Debtors.Single(s => s.DebtorID == invoice.DebtorID);
                        AuthMessageSender email  = new AuthMessageSender(_settings);
                        await email.SendInvoiceEmailAsync(debtor.Email);
                    }
                    else if (invoice.CompanyID is int)
                    {
                        Company           company = _context.Companies.Single(s => s.CompanyID == invoice.CompanyID);
                        AuthMessageSender email   = new AuthMessageSender(_settings);
                        await email.SendInvoiceEmailAsync(company.Email);
                    }
                }

                return(RedirectToAction("Index"));
            }

            //Create selectlist with all categories
            var categories = _context.Categories
                             .Select(s => new SelectListItem {
                Value = s.CategoryID.ToString(),
                Text  = s.CategoryName
            });

            //Create selectlist with all companies
            var companies = _context.Companies
                            .Select(s => new SelectListItem {
                Value = s.CompanyID.ToString(),
                Text  = s.CompanyName.ToString() + " in " + s.City.ToString()
            });

            //Create selectlist with all debtor
            var debtors = _context.Debtors
                          .Select(s => new SelectListItem {
                Value = s.DebtorID.ToString(),
                Text  = s.FullName.ToString() + " in " + s.City.ToString()
            });

            //Viewbags and viewdata
            ViewBag.Categories    = new SelectList(categories, "Value", "Text");
            ViewData["CompanyID"] = new SelectList(companies, "Value", "Text", invoice.CompanyID);
            ViewData["DebtorID"]  = new SelectList(debtors, "Value", "Text", invoice.DebtorID);

            return(View(invoice));
        }