public ActionResult DeleteConfirmed(int id) { Line_Item line_Item = db.Line_Item.Find(id); db.Line_Item.Remove(line_Item); db.SaveChanges(); return(RedirectToAction("Index")); }
// This test is responsible for checking the constructor public void Line_ItemTest_ConstructorWithNoValues_ShouldPass() { // Arrange // Act Line_Item lineItem = new Line_Item(); // Assert Assert.IsNotNull(lineItem); }
public ActionResult Edit([Bind(Include = "line_item_id,invoice_id,game_id,quantity,price")] Line_Item line_Item) { if (ModelState.IsValid) { db.Entry(line_Item).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.game_id = new SelectList(db.Games, "game_id", "game_name", line_Item.game_id); ViewBag.invoice_id = new SelectList(db.Invoices, "invoice_id", "invoice_id", line_Item.invoice_id); return(View(line_Item)); }
// This test is responsible for checking the quantity field public void Line_ItemTest_QuantityWithCorrectType_ShouldPass() { // Arrange Line_Item lineItem = new Line_Item(); int expected = 2; int actual; // Act lineItem.quantity = expected; // Assert actual = lineItem.quantity; Assert.AreEqual(expected, actual); }
// This test is responsible for checking the game_id field public void Line_ItemTest_GameIDWithCorrectType_ShouldPass() { // Arrange Line_Item lineItem = new Line_Item(); int expected = 5; int actual; // Act lineItem.game_id = expected; // Assert actual = lineItem.game_id; Assert.AreEqual(expected, actual); }
// GET: Line_Item/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Line_Item line_Item = db.Line_Item.Find(id); if (line_Item == null) { return(HttpNotFound()); } return(View(line_Item)); }
[Authorize(Roles = "Customer, Admin, Employee, Member")] //user must be logged in/registered in order to check out public ActionResult Checkout(int address_id, int credit_card_id) { int user_id = db.Users.Where(u => u.username == this.User.Identity.Name).FirstOrDefault().user_id; Cart cart = GetCart(); if (cart.Items == null || cart.Items.Count() == 0) // if there aren't any items in the cart - send back to index and show message { TempData["Message"] = "Invalid Submission: You cannot checkout without any items in your cart..."; return(Checkout()); } else { // create invoice + populate with data from select list in view Invoice invoice = new Invoice(); invoice.user_id = user_id; invoice.credit_card_id = credit_card_id; invoice.invoice_date = DateTime.Now; // add invoice and save changes db.Invoices.Add(invoice); db.SaveChanges(); // get id of most recently inserted invoice int invoiceNumber = db.Invoices.Max(i => i.invoice_id); // create invoice address based on user's selected address Invoice_Address invoiceAddress = new Invoice_Address(); invoiceAddress.address_id = address_id; invoiceAddress.invoice_id = invoiceNumber; invoiceAddress.is_billing_address = true; db.Invoice_Address.Add(invoiceAddress); // get items in cart foreach (CartLineItem item in cart.Items) { // create line items and add to db Line_Item line_item = new Line_Item(); line_item.invoice_id = invoiceNumber; line_item.game_id = item.Game.game_id; line_item.quantity = item.Quantity; line_item.price = item.Game.list_price; db.Line_Item.Add(line_item); db.SaveChanges(); } // clear out cart data Session["Cart"] = new Cart(); return(RedirectToAction("DisplayUserInvoice", "Invoices", new { id = invoiceNumber })); } }
// GET: Line_Item/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Line_Item line_Item = db.Line_Item.Find(id); if (line_Item == null) { return(HttpNotFound()); } ViewBag.game_id = new SelectList(db.Games, "game_id", "game_name", line_Item.game_id); ViewBag.invoice_id = new SelectList(db.Invoices, "invoice_id", "invoice_id", line_Item.invoice_id); return(View(line_Item)); }