Exemplo n.º 1
0
        // GET: Home
        public ActionResult Index()
        {
            try
            {
                Categolory         sachbanchay = db.Categolorys.Single(x => x.CategoloryName.Equals("Sách bán chạy"));
                IEnumerable <Book> model       = db.Books.Where(x => x.Categolorys.Any(c => c.CategoloryID == sachbanchay.CategoloryID));
                ViewData["sellrun"] = model;
            }
            catch (Exception e)
            {
                e.GetBaseException();
            }

            try
            {
                Categolory         banchaytrongthang = db.Categolorys.Single(x => x.CategoloryName.Equals("Sách bán chạy trong tháng"));
                IEnumerable <Book> model2            = db.Books.Where(x => x.Categolorys.Any(c => c.CategoloryID == banchaytrongthang.CategoloryID));
                ViewData["sellinmonth"] = model2;
            }
            catch (Exception e)
            {
                e.GetBaseException();
            }
            try
            {
                Categolory         sachsapphathanh = db.Categolorys.Single(x => x.CategoloryName.Equals("Sách sắp phát hành"));
                IEnumerable <Book> model3          = db.Books.Where(x => x.Categolorys.Any(c => c.CategoloryID == sachsapphathanh.CategoloryID));
                ViewData["sellPhatHang"] = model3;
            }
            catch (Exception e)
            {
                e.GetBaseException();
            }

            ////int sachsapphathanh = 0;
            ////int sachbanchaytronthanh = 0;
            ////int sachbanchay = 0;
            ////foreach (var item in list)
            ////{
            ////    sachbanchay = item.CategoloryID
            ////}



            // decive model3 to 2 path


            List <CartItem> cartItems = (List <CartItem>)Session["CartSession"];

            if (cartItems != null)
            {
                ViewBag.itemCart = cartItems.Count;
            }
            else
            {
                ViewBag.itemCart = 0;
            }
            return(View());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Categolory categolory = db.Categolorys.Find(id);

            db.Categolorys.Remove(categolory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "CategoloryID,CategoloryName")] Categolory categolory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categolory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categolory));
 }
        public ActionResult Create([Bind(Include = "CategoloryID,CategoloryName")] Categolory categolory)
        {
            if (ModelState.IsValid)
            {
                db.Categolorys.Add(categolory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(categolory));
        }
        // GET: Admin/Categolories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Categolory categolory = db.Categolorys.Find(id);

            if (categolory == null)
            {
                return(HttpNotFound());
            }
            return(View(categolory));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "BookName,BookPrices,BookDescription,BookDateUpdate,BookQuantity,BookDiscount,TopicRefId,ProductionRefId,AuthorRefId,Categolorys,BookImage")] Book book)
        {
            if (ModelState.IsValid)
            {
                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    if (file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        book.BookImage = Path.Combine(
                            Server.MapPath("~/Content/image"), fileName);
                        file.SaveAs(book.BookImage);
                        book.BookImage = Path.GetFileName(file.FileName);
                    }
                }

                try
                {
                    int        idcatefory = int.Parse(Request.Form["CategoloryRefID"]);
                    Categolory categolory = db.Categolorys.Find(idcatefory);
                    book.Categolorys.Add(categolory);
                }
                catch (Exception)
                {
                    db.Books.Add(book);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));

                    throw;
                }

                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AuthorRefId     = new SelectList(db.Authors, "AuthorID", "AuthorName", book.AuthorRefId);
            ViewBag.ProductionRefId = new SelectList(db.Productions, "ProductionID", "ProductionName", book.ProductionRefId);
            ViewBag.TopicRefId      = new SelectList(db.Topics, "TopicID", "TopicName", book.TopicRefId);
            return(View(book));
        }
Exemplo n.º 7
0
        public ActionResult Edit([Bind(Include = "BookID,BookName,BookPrices,BookDescription,BookDateUpdate,BookQuantity,BookDiscount,TopicRefId,ProductionRefId,AuthorRefId,Categolorys,BookImage")] Book book)
        {
            if (ModelState.IsValid)
            {
                int tam        = book.BookID;
                int idcatefory = int.Parse(Request.Form["CategoloryRefID"]);

                Categolory Categolory = db.Categolorys.Single(c => c.CategoloryID == idcatefory);

                if (Request.Files.Count > 0)
                {
                    HttpPostedFileBase file = Request.Files[0];
                    if (file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        book.BookImage = Path.Combine(
                            Server.MapPath("~/Content/image"), fileName);
                        file.SaveAs(book.BookImage);
                        book.BookImage = Path.GetFileName(file.FileName);
                    }
                }

                Categolory.Books.Add(book);
                book.Categolorys.Add(Categolory);
                db.Entry(book).State = EntityState.Modified;
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    e.GetBaseException();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.AuthorRefId     = new SelectList(db.Authors, "AuthorID", "AuthorName", book.AuthorRefId);
            ViewBag.ProductionRefId = new SelectList(db.Productions, "ProductionID", "ProductionName", book.ProductionRefId);
            ViewBag.TopicRefId      = new SelectList(db.Topics, "TopicID", "TopicName", book.TopicRefId);
            ViewBag.CategoloryRefID = new SelectList(db.Categolorys, "CategoloryID", "CategoloryName", book.Categolorys);
            return(View(book));
        }