예제 #1
0
        public BooksCategoryBooksViewModel GetBooksCategoryBooks(Guid booksCatID)
        {
            BooksCategoryBooksViewModel booksCategoryBooksViewModel = new BooksCategoryBooksViewModel();
            BooksCategory booksCategory = booksLibraryDataContext.BooksCategories.FirstOrDefault(x => x.IDBooksCategory == booksCatID);

            if (booksCategory != null)
            {
                booksCategoryBooksViewModel.Genre            = booksCategory.Genre;
                booksCategoryBooksViewModel.ChildAppropriate = booksCategory.ChildAppropriate;
                IQueryable <Book> catBooks = booksLibraryDataContext.Books.Where(x => x.IDBooksCategory == booksCatID);

                foreach (Book dbBook in catBooks)
                {
                    Models.BookModel bookModel = new Models.BookModel();

                    bookModel.Name           = dbBook.Name;
                    bookModel.Author         = dbBook.Author;
                    bookModel.Publisher      = dbBook.Publisher;
                    bookModel.NumberOfCopies = dbBook.NumberOfCopies;
                    bookModel.imageUrl       = dbBook.imageUrl;

                    booksCategoryBooksViewModel.Books.Add(bookModel);
                }
            }
            return(booksCategoryBooksViewModel);
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            BooksCategory booksCategory = db.BooksCategorys.Find(id);

            db.BooksCategorys.Remove(booksCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public int DeleteBookCategory(int _BookCategoryID)
        {
            BooksCategory BooksCategoryToDelete = context
                                                  .BooksCategories.SingleOrDefault(x => x.BooksCategoryID == _BookCategoryID);

            context.BooksCategories.Remove(BooksCategoryToDelete);
            return(context.SaveChanges());
        }
        public int UpdateBooksCategory(BooksCategory __BooksCategory)
        {
            BooksCategory BooksCategoryToUpdate = context.BooksCategories.SingleOrDefault(x => x.BooksCategoryID == __BooksCategory.BooksCategoryID);

            BooksCategoryToUpdate.Category = __BooksCategory.Category;

            return(context.SaveChanges());
        }
        public HttpResponseMessage UpdateBooksCategory([FromBody] BooksCategory _BookCategory)
        {
            BookCategoryRepository ctxBooksCategory = new BookCategoryRepository();

            ctxBooksCategory.UpdateBooksCategory(_BookCategory);
            HttpResponseMessage ms = Request.CreateResponse(HttpStatusCode.OK);

            ms.Headers.Location = new Uri(Request.RequestUri + "/" + (_BookCategory.BooksCategoryID).ToString());
            return(ms);
        }
예제 #6
0
 public ActionResult Edit([Bind(Include = "Id,Name")] BooksCategory booksCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(booksCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(booksCategory));
 }
예제 #7
0
        public ActionResult Create([Bind(Include = "Id,Name")] BooksCategory booksCategory)
        {
            if (ModelState.IsValid)
            {
                db.BooksCategorys.Add(booksCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(booksCategory));
        }
        public HttpResponseMessage GetBooksCategoryByID(int id)
        {
            BookCategoryRepository ctxBooksCategory = new BookCategoryRepository();

            BooksCategory _BooksCategory = ctxBooksCategory.GetBooksCategory().FirstOrDefault(x => x.BooksCategoryID == id);

            if (_BooksCategory != null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, _BooksCategory));
            }
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item not found"));
            }
        }
예제 #9
0
        // GET: BooksCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BooksCategory booksCategory = db.BooksCategorys.Find(id);

            if (booksCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(booksCategory));
        }
 public int InsertBooksCategory(BooksCategory _BooksCategory)
 {
     context.BooksCategories.Add(_BooksCategory);
     return(context.SaveChanges());
 }