示例#1
0
        //listing details popup getter
        public ActionResult ListingDetails(string seller, decimal?price, MvcApplication1.Models.Book clickedBook, int listID)
        {
            //if (clickedBook.CourseID > 0)
            //{
            //    using (TestDbContext db = new TestDbContext())
            //    {
            //        clickedBook.Course = db.Courses.Find(clickedBook.CourseID);
            //    }
            //}

            //currently seller is being passed as an ID, this will probably change


            //ViewData["seller"] = (seller == null) ? "" : seller;
            ViewData["seller"] = UserUtils.UserIDtoName(Convert.ToInt32(seller));
            ViewData["price"]  = (price == null) ? 0m : price;
            ViewData["listID"] = listID;
            Book resolvedBook = null;

            using (TestDbContext db = new TestDbContext())
            {
                var books = (from b in db.Books
                             where b.BookID == clickedBook.BookID
                             select b).ToList();
                if (books.Count() > 0)
                {
                    resolvedBook = books[0];

                    //LAZY LOAD COURSE
                    resolvedBook.Course = resolvedBook.Course;
                }
            }
            ViewData["book"] = resolvedBook;
            return(View("~/Views/Shared/ListingDetails.cshtml"));
        }
示例#2
0
        //book details popup getter
        public ActionResult BookDetails(MvcApplication1.Models.Book clickedBook = null)//)
        {
            if (clickedBook == null)
            {
                return(Content("error"));
            }
            if (clickedBook.CourseID > 0)
            {
                using (TestDbContext db = new TestDbContext())
                {
                    clickedBook.Course = db.Courses.Find(clickedBook.CourseID);
                }
            }


            //get available listings for book

            Book resolvedBook = null;

            using (TestDbContext db = new TestDbContext())
            {
                int accountid = UserUtils.UserNametoID(User.Identity.Name);

                IQueryable <Book> books = from b in db.Books
                                          where b.BookID == clickedBook.BookID
                                          select b;
                if (books.Count() > 0)
                {
                    resolvedBook = books.First();
                    //probably more loading here than needed
                    resolvedBook.Course       = resolvedBook.Course;
                    resolvedBook.Course.Books = resolvedBook.Course.Books;
                    resolvedBook.Listings     = resolvedBook.Listings;
                }
            }


            //pass back available listings
            ViewData["book"] = resolvedBook;
            return(View("~/Views/Shared/BookDetails.cshtml"));
        }
        public ActionResult Create(Book book)
        {
            if (ModelState.IsValid)
            {
                foreach (string file in Request.Files)
                {
                    var filePosted = Request.Files[file];
                    var fileName = Path.GetTempPath() + Path.GetFileName(filePosted.FileName);
                    filePosted.SaveAs(fileName);

                    book.Image = System.IO.File.ReadAllBytes(fileName);
                }

                db.Books.Add(book);
                db.SaveChanges();

                System.IO.File.WriteAllBytes(Server.MapPath("~/Images/" + book.Id + ".jpg"), book.Image);

                return RedirectToAction("Index");
            }

            return View(book);
        }
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(book);
 }