예제 #1
0
        public ActionResult Edit(Book book)
        {
            //Check user is logged in
            if (WebSecurity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    db.Entry(book).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.AuthorList   = new SelectList(db.Authors, "AuthorId", "Publisher", book.AuthorId);
                ViewBag.SupplierList = new SelectList(db.Suppliers, "SupplierId", "SupplierName", book.SupplierId);
                return(View(book));
            }
            else
            {
                //Return the user to the login page if there is no user id
                return(RedirectToAction("Login", "Account"));
            }
        }
예제 #2
0
        //Get the Order detail from the inherited order model and post the return view for order and order line item from the ids
        public ActionResult Details(int id = 0)
        {
            //Check user is logged in
            if (WebSecurity.IsAuthenticated)
            {
                Order order = db.Orders.Find(id);

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

                db.Entry(order).Reference(x => x.Store).Load();
                db.Entry(order).Collection(x => x.OrderLines).Load();

                //Get the store ids from view
                ViewBag.BookList  = new SelectList(db.Books, "BookId", "Title");
                ViewBag.StoreList = new SelectList(db.Stores, "StoreId", "StoreOwner", order.StoreId);

                //Get the order details view page
                return(View(order));
            }
            else
            {
                //Return the user to the login page if there is no user id
                return(RedirectToAction("Login", "Account"));
            }
        }