public ActionResult Index(int prodID, int ordId) { Product prod = db.Product.Find(prodID); Order ord = db.Order.Find(ordId); //if (prod == null || ord == null) //{ // return HttpNotFound(); //} OrderAndProducts orderAndProducts = new OrderAndProducts(); orderAndProducts.Order_Id = ord.OrderId; orderAndProducts.Product_Id = prod.ProductId; orderAndProducts.Order = ord; orderAndProducts.Product = prod; if (ModelState.IsValid) { db.OrderAndProducts.Add(orderAndProducts); db.SaveChanges(); return(RedirectToAction("index/" + ord.OrderId, "Orders")); } ViewBag.Order_Id = new SelectList(db.Order, "Id", "UserName", orderAndProducts.Order_Id); ViewBag.Product_Id = new SelectList(db.Product, "Id", "Name", orderAndProducts.Product_Id); return(RedirectToAction("index", "Orders")); }
public ActionResult DeleteConfirmed(int id) { OrderAndProducts orderAndProducts = db.OrderAndProducts.Find(id); db.OrderAndProducts.Remove(orderAndProducts); db.SaveChanges(); return(RedirectToAction("index/" + ViewBag.Order_Id, "Orders")); }
public ActionResult Edit([Bind(Include = "Id,Product_Id,Order_Id")] OrderAndProducts orderAndProducts) { if (ModelState.IsValid) { db.Entry(orderAndProducts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderAndProducts)); }
public ActionResult Create([Bind(Include = "Id,Product_Id,Order_Id")] OrderAndProducts orderAndProducts) { if (ModelState.IsValid) { db.OrderAndProducts.Add(orderAndProducts); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(orderAndProducts)); }
// GET: OrderAndProducts/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OrderAndProducts orderAndProducts = db.OrderAndProducts.Find(id); if (orderAndProducts == null) { return(HttpNotFound()); } return(View(orderAndProducts)); }
// GET: Orders/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Order order = db.Order.Find(id); if (order == null) { return(HttpNotFound()); } IEnumerable <Product> prods = db.Product.ToList(); //Example IEnumerable <Order> orders = db.Order.Where(x => x.CustomerId == 1); var model = new OrderAndProducts { }; return(View(model)); }
public OrdersSearchOrderVM() { OrderAndProducts = new OrderAndProducts(); }