Ejemplo n.º 1
0
        public ActionResult DeleteConfirmed(int?bookId, int?categoryId)
        {
            BooksCategories booksCategories = db.BooksCategories.Find(bookId, categoryId);

            db.BooksCategories.Remove(booksCategories);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "BookId,CategoryId")] BooksCategories booksCategories)
        {
            if (ModelState.IsValid)
            {
                db.BooksCategories.Add(booksCategories);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BookId     = new SelectList(db.Books, "BookID", "BookTitle", booksCategories.BookId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryID", "CategoryName", booksCategories.CategoryId);
            return(View(booksCategories));
        }
Ejemplo n.º 3
0
        // GET: BooksCategories/Delete/5
        public ActionResult Delete(int?bookId, int?categoryId)
        {
            if (bookId == null || categoryId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BooksCategories booksCategories = db.BooksCategories.Find(bookId, categoryId);

            if (booksCategories == null)
            {
                return(HttpNotFound());
            }
            return(View(booksCategories));
        }
Ejemplo n.º 4
0
        // GET: BooksCategories/Edit/5
        public ActionResult Edit(int?bookId, int?categoryId)
        {
            if (bookId == null && categoryId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BooksCategories booksCategories = db.BooksCategories.Find(bookId, categoryId);

            if (booksCategories == null)
            {
                return(HttpNotFound());
            }
            ViewBag.BookId     = new SelectList(db.Books, "BookID", "BookTitle", booksCategories.BookId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryID", "CategoryName", booksCategories.CategoryId);
            return(View(booksCategories));
        }
Ejemplo n.º 5
0
        public ActionResult Edit([Bind(Include = "BookId,CategoryId")] BooksCategories booksCategories)
        {
            if (ModelState.IsValid)
            {
                var services = db.BooksCategories.Where(b => b.BookId == booksCategories.BookId)
                               .Where(c => c.CategoryId == booksCategories.CategoryId);

                foreach (var item in services)
                {
                    db.BooksCategories.Remove(item);
                }
                db.BooksCategories.Add(booksCategories);
                db.Entry(booksCategories).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.BookId     = new SelectList(db.Books, "BookID", "BookTitle", booksCategories.BookId);
            ViewBag.CategoryId = new SelectList(db.Categories, "CategoryID", "CategoryName", booksCategories.CategoryId);
            return(View(booksCategories));
        }
Ejemplo n.º 6
0
        // GET: BooksCategories/Details/5
        public ActionResult Details(int?bookId, int?categoryId)
        {
            if (bookId == null && categoryId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BooksCategories booksCategories = db.BooksCategories.Find(bookId, categoryId);

            if (booksCategories == null)
            {
                return(HttpNotFound());
            }
            BookCategoriesViewModel vm = new BookCategoriesViewModel()
            {
                Books          = db.Books.SingleOrDefault(b => b.BookID == booksCategories.BookId),
                Categories     = db.Categories.SingleOrDefault(c => c.CategoryID == booksCategories.CategoryId),
                CategoriesList = null
            };

            return(View(vm));
        }
Ejemplo n.º 7
0
        public ActionResult Create(BooksCategoryToSelectFromViewModel bookAndCategpries /*,int [] categoriesIds*/)
        {
            if (ModelState.IsValid)
            {
                if (bookAndCategpries.Book.Quantity > 0)
                {
                    bookAndCategpries.Book.StatusID = 1;
                }
                else
                {
                    bookAndCategpries.Book.StatusID = 2;
                }
                if (bookAndCategpries.Book.bookCoverImage != null)
                {
                    var fileName      = Path.GetFileNameWithoutExtension(bookAndCategpries.Book.bookCoverImage.FileName);
                    var fileExtention = Path.GetExtension(bookAndCategpries.Book.bookCoverImage.FileName);
                    fileName = fileName + DateTime.Now.ToString("yymmssff") + fileExtention;

                    bookAndCategpries.Book.BookCover = "~/Images/bookCovers/" + fileName;
                    fileName = Path.Combine(Server.MapPath("~/Images/bookCovers/"), fileName);
                    bookAndCategpries.Book.bookCoverImage.SaveAs(fileName);
                }

                if (bookAndCategpries.SelectedCategory.SelectedCategories.Count() != 0)
                {
                    foreach (var item in bookAndCategpries.SelectedCategory.SelectedCategories)
                    {
                        BooksCategories bookCategory = new BooksCategories()
                        {
                            BookId     = bookAndCategpries.Book.BookID,
                            CategoryId = item
                        };
                        db.BooksCategories.Add(bookCategory);
                        db.SaveChanges();
                    }
                }
                //if (bookAndCategpries.SelectedCountry.SelectedCountries != 0)
                //{
                //    bookAndCategpries.Book.CountryID = bookAndCategpries.SelectedCountry.SelectedCountries;
                //}
                bookAndCategpries.Book.CountryID = bookAndCategpries.SelectedCountry.SelectedCountries[0];

                db.Books.Add(bookAndCategpries.Book);
                db.SaveChanges();

                //foreach (var item in categoriesIds)
                //{
                //    BooksCategories bookCategory = new BooksCategories()
                //    {
                //        BookId = book.BookID,
                //        CategoryId = item
                //    };
                //    db.BooksCategories.Add(bookCategory);
                //}


                return(RedirectToAction("Index"));
            }

            ViewBag.CountryID   = new SelectList(db.Countries, "CountryID", "CountryName", bookAndCategpries.Book.CountryID);
            ViewBag.FormID      = new SelectList(db.Forms, "FormID", "FormTitle", bookAndCategpries.Book.FormID);
            ViewBag.LanguageID  = new SelectList(db.Languages, "LanguageID", "LanguageName", bookAndCategpries.Book.LanguageID);
            ViewBag.PublisherID = new SelectList(db.Publishers, "PublisherID", "PublisherName", bookAndCategpries.Book.PublisherID);
            ViewBag.StatusID    = new SelectList(db.Status, "StatusID", "StatusName", bookAndCategpries.Book.StatusID);
            return(View(bookAndCategpries));
        }