Beispiel #1
0
        // GET: Invoices/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var invoice = _repository.GetInvoice(id);

            if (invoice == null)
            {
                return(HttpNotFound());
            }

            EditInvoiceVm vm = new EditInvoiceVm
            {
                Id          = invoice.Id,
                InvoiceDate = invoice.Invoice_date,
                DueDate     = invoice.Due_date,
                Paid        = invoice.Paid,
                InvoiceItem = from e in invoice.InvoiceItem
                              select new InvoiceItemVm
                {
                    Id       = e.Id,
                    Name     = e.Name,
                    Price    = e.Price,
                    Quantity = e.Quantity
                }
            };

            return(View(vm));
        }
Beispiel #2
0
        public ActionResult Edit(EditInvoiceVm invoiceVm)
        {
            if (ModelState.IsValid)
            {
                Invoice invoice = new Invoice()
                {
                    Id           = invoiceVm.Id,
                    Invoice_date = invoiceVm.InvoiceDate,
                    Due_date     = invoiceVm.DueDate,
                    Paid         = invoiceVm.Paid
                };

                _repository.EditInvoice(invoice);
                return(RedirectToAction("Index"));
            }
            return(View(invoiceVm));
        }