public ActionResult Create()
        {
            // initialize invoice with defaults
            Invoice Invoice = new Invoice()
            {
                InvoiceId = 0,
                EntryDate = DateTime.UtcNow.Date, // TODO: localize this to the user's timezone
                Items = new List<InvoiceItem>()
            };

            PadItemsList(Invoice);
            PopulateEditViewBagProperties(false);
            return View(Invoice);
        }
 private void VerifyInvoiceFilter(ICurrentUser user, Invoice invoice, bool expectedResult)
 {
     var filter = DataContextExtensions.GetInvoiceFilterForCurrentUser(user);
     var actualResult = filter(invoice);
     Assert.AreEqual(expectedResult, actualResult);
 }
Beispiel #3
0
 public Invoice Remove(Invoice entity)
 {
     Entry(entity).State = System.Data.EntityState.Deleted;
     return entity;
 }
Beispiel #4
0
 public DbEntityEntry<Invoice> Entry(Invoice entity)
 {
     return db.Entry<Invoice>(entity);
 }
Beispiel #5
0
 public Invoice Add(Invoice entity)
 {
     return db.Invoices.Add(entity);
 }
 public ActionResult Create(Invoice invoice)
 {
     return Edit(invoice);
 }
 private IEnumerable<Cell> GetInvoiceCells(Invoice invoice)
 {
     yield return new Cell(invoice.ServiceDate.ToShortDateString());
     yield return new Cell(invoice.EntryDate.ToShortDateString());
     yield return new Cell(invoice.Site.ToString());
     yield return new Cell(invoice.Servicer.Name);
     yield return new Cell(invoice.FrtBill);
     yield return new Cell(invoice.KeyRec);
     yield return new Cell(invoice.PurchaseOrder);
     yield return new Cell(invoice.Total.ToString("0.00"));
 }
 private static void PadItemsList(Invoice invoice)
 {
     for (int i = invoice.Items == null ? 0 : invoice.Items.Count; i < 10; ++i)
     {
         invoice.Items.Add(new InvoiceItem() { InvoiceId = invoice.InvoiceId, InvoiceItemId = i });
     }
 }
        public ActionResult Edit(Invoice invoice)
        {
            try
            {
                if (invoice.Items == null)
                {
                    invoice.Items = new List<InvoiceItem>();
                }
                else
                {
                    invoice.Items.RemoveAll(item => item.IsEmpty);
                }

                invoice.LogDate = DateTime.UtcNow;
                invoice.LogUserId = MvcExtensions.CurrentUser(System.Web.HttpContext.Current).UserId;

                if (ModelState.IsValid)
                {
                    repo.Entry(invoice).State = invoice.InvoiceId > 0 ? EntityState.Modified : EntityState.Added;
                    repo.SaveChanges();

                    var ExistingItemIds = repo.InvoiceItems.Where(i => i.InvoiceId == invoice.InvoiceId).Select(i => i.InvoiceItemId).ToList();

                    foreach (var Item in invoice.Items)
                    {
                        repo.Entry(Item).State = ExistingItemIds.Contains(Item.InvoiceItemId) ? EntityState.Modified : EntityState.Added;
                    }
                    repo.SaveChanges();
                    TempData["Message"] = "Invoice Saved";

                    if (Request.Form["Save"] == "Save and Add Another")
                    {
                        return RedirectToAction("Create", new { from = Request["from"] });
                    }
                    if (Request.QueryString["from"] == "details")
                    {
                        return RedirectToAction("Details", new { id = invoice.InvoiceId });
                    }
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["Message"] = string.Format("Error saving invoice ({0})", ex.Message);
            }
            PopulateEditViewBagProperties(false);
            return View(invoice);
        }