Exemplo n.º 1
0
        public ActionResult AddToCart(int uniqueId)
        {
            ChildrenBook targetBook = null;

            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                targetBook = dbContext.ChildrenBooks.SingleOrDefault(c => c.UniqueId == uniqueId);
            }
            return(View("OrderReview", targetBook));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id)
        {
            ChildrenBook targetBook = null;

            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                targetBook = dbContext.ChildrenBooks.SingleOrDefault(b => b.Id == id);
            }

            return(View("EditChildrenBook", targetBook));
        }
Exemplo n.º 3
0
 public ActionResult Add(ChildrenBook childrenBook)
 {
     using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
     {
         if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 100)
         {
             string fileName          = Path.GetFileName(this.Request.Files[0].FileName);
             string filePathOfWebsite = "~/Images/ChildrenBookCover" + fileName;
             childrenBook.CoverImagePath = filePathOfWebsite;
             this.Request.Files[0].SaveAs(this.Server.MapPath(filePathOfWebsite));
         }
         dbContext.ChildrenBooks.Add(childrenBook);
         dbContext.SaveChanges();
     }
     return(RedirectToAction("Show"));
 }
Exemplo n.º 4
0
 public ActionResult Edit(ChildrenBook ChildrenBook)
 {
     using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
     {
         if (this.Request.Files != null && this.Request.Files.Count > 0 && this.Request.Files[0].ContentLength > 0 && this.Request.Files[0].ContentLength < 1024 * 100)
         {
             string fileName          = Path.GetFileName(this.Request.Files[0].FileName);
             string filePathOfWebsite = "~/Images/ChildrenBookCover/" + fileName;
             ChildrenBook.CoverImagePath = filePathOfWebsite;
             this.Request.Files[0].SaveAs(this.Server.MapPath(filePathOfWebsite));//无法添加图片,路径名不对。
         }
         dbContext.ChildrenBooks.Attach(ChildrenBook);
         dbContext.Entry(ChildrenBook).State = System.Data.Entity.EntityState.Modified;
         dbContext.SaveChanges();
     }
     return(RedirectToAction("Show"));
 }
Exemplo n.º 5
0
 public ActionResult Delete(int id)
 {
     using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
     {
         ChildrenBook targetBook = null;
         targetBook = dbContext.ChildrenBooks.SingleOrDefault(b => b.Id == id);
         if (targetBook == null)
         {
             return(View("Warning"));
         }
         else
         {
             dbContext.ChildrenBooks.Remove(targetBook);
             dbContext.SaveChanges();
         }
     }
     return(RedirectToAction("Show"));
 }