Пример #1
0
        public ActionResult AddToCart(int uniqueId)
        {
            SingleBook    singlebook          = new SingleBook();
            CSBook        CStargetBook        = null;
            EconomicsBook EconomicstargetBook = null;
            NovelBook     NoveltargetBook     = null;

            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                if (uniqueId < 2000)
                {
                    CStargetBook      = dbContext.CSBooks.SingleOrDefault(n => n.UniqueId == uniqueId);
                    singlebook.CSBook = CStargetBook;
                }
                else if (uniqueId > 2000 & uniqueId < 3000)
                {
                    EconomicstargetBook      = dbContext.EconomicsBooks.SingleOrDefault(n => n.UniqueId == uniqueId);
                    singlebook.Economicsbook = EconomicstargetBook;
                }
                else
                {
                    NoveltargetBook      = dbContext.NovelBooks.SingleOrDefault(n => n.UniqueId == uniqueId);
                    singlebook.NovelBook = NoveltargetBook;
                }
            }

            return(View("OrderReview", singlebook));
        }
Пример #2
0
        public void TestMethod2()
        {
            foreach (OffNovelBook book in BookStore2.BookList)
            {
                NovelBook novelBook = book;
                Debug.WriteLine("书名: " + novelBook.GetName());
                Debug.WriteLine("作者: " + novelBook.GetAuthor());
                Debug.WriteLine("原价: " + novelBook.GetPrice());

                OffNovelBook offNovelBook = book;
                Debug.WriteLine("打折价: " + offNovelBook.GetPrice());
            }
            //运行结果:
            //书名: 书1
            //作者: 作者
            //原价: 24
            //打折价: 19.2
            //书名: 书2
            //作者: 作者2
            //原价: 60
            //打折价: 54
            //书名: 书3
            //作者: 作者3
            //原价: 99
            //打折价: 89.1
        }
Пример #3
0
 public void TestMethod1()
 {
     foreach (NovelBook book in BookStore.BookList)
     {
         NovelBook novelBook = book;
         Debug.WriteLine("书名: " + novelBook.GetName());
         Debug.WriteLine("作者: " + novelBook.GetAuthor());
         Debug.WriteLine("原价: " + novelBook.GetPrice());
     }
 }
Пример #4
0
        public ActionResult Edit(int id)
        {
            NovelBook targetNovel = null;

            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                targetNovel = dbContext.NovelBooks.SingleOrDefault(n => n.Id == id);
            }

            return(View("EditNovel", targetNovel));
        }
Пример #5
0
        public ActionResult AddToCart(int uniqueId)
        {
            NovelBook targetBook = null;

            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                targetBook = dbContext.NovelBooks.SingleOrDefault(n => n.UniqueId == uniqueId);
            }

            return(View("OrderReview", targetBook));
        }
Пример #6
0
        public ActionResult Add(NovelBook novel)
        {
            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/NovelCovers/" + fileName;
                    novel.CoverImagePath = filePathOfWebsite;
                    this.Request.Files[0].SaveAs(this.Server.MapPath(filePathOfWebsite));
                }

                dbContext.NovelBooks.Add(novel);
                dbContext.SaveChanges();
            }

            return(RedirectToAction("Show", new { pageNumber = 1 }));
        }
Пример #7
0
        public ActionResult Delete(int id)
        {
            using (Group001BookstoreEntities dbContext = new Group001BookstoreEntities())
            {
                NovelBook targetNovel = null;
                targetNovel = dbContext.NovelBooks.SingleOrDefault(n => n.Id == id);
                if (targetNovel == null)
                {
                    return(View("Warning"));
                }
                else
                {
                    dbContext.NovelBooks.Remove(targetNovel);
                    dbContext.SaveChanges();
                }
            }

            return(RedirectToAction("Show", new { pageNumber = 1 }));
        }