Ejemplo n.º 1
0
        public IHttpActionResult PutBook(int id, Book book)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != book.Id)
            {
                return(BadRequest());
            }

            db.Entry(book).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BookExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create(FormCollection collection)
        {
            Book book = new Book();

            if (ModelState.IsValau_id)
            {
                book.au_lname = collection["au_lname"].ToString();
                book.au_fname = collection["au_fname"].ToString();
                book.phone    = Convert.ToDecimal(collection["phone"]);
                book.address  = collection["address"].ToString();
                book.city     = collection["city"].ToString();
                book.state    = collection["state"].ToString();
                book.zip      = collection["zip"].ToString();
                book.contract = collection["contract"].ToString();


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

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(book));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                Book book = new Book();
                if (ModelState.IsValid)
                {
                    book.Title = collection["Title"].ToString();
                    book.ISBN  = collection["ISBN"].ToString();
                    book.Price = Convert.ToDecimal(collection["Price"]);

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


                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(book));
                }
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,Title,ISBN,Author,Description")] Book book)
 {
     if (ModelState.IsValid)
     {
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Details", new { id = book.Id }));
     }
     return(View(book));
 }
Ejemplo n.º 5
0
 public ActionResult Create(BookModel model)
 {
     if (ModelState.IsValid)
     {
         objBookDb.Entry(model).State = EntityState.Added;
         objBookDb.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,ISBN,Title,Author,Genre,Price,Stock")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Book.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "BookID,Category,Name,Numberfcopies,AuthorID,Price,PublishDate")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 8
0
        public ActionResult Create(BooksDB bookdb)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(bookdb);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bookdb));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "Id,Name,PublishedDate,Price")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Book.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 10
0
        public ActionResult Create([Bind(Include = "ID,Title,FinishedReadingDate")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 11
0
        public ActionResult Create([Bind(Include = "ID,Title,ReleaseDate,Theme,Price")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 12
0
        public ActionResult Create([Bind(Include = "ISBN,AuthorID,Title,EditionNumber,Copyright,FirstName,LastName")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 13
0
        public ActionResult Create([Bind(Include = "BookID,Title,Author,Edition,PublishYear,Price,Quantity")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 14
0
        public ActionResult Create([Bind(Include = "ID,ISBN,Title,AuthorID,Publisher,PublishDate,Price")] book book)
        {
            if (ModelState.IsValid)
            {
                db.books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 15
0
        public ActionResult Create([Bind(Include = "ID,ISBN,Title,Author,Publisher,Summary,Notes")] Book book)
        {
            if (ModelState.IsValid)
            {
                book.isAvailable = true; // now this book is available to lend
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(book));
        }
Ejemplo n.º 16
0
        public ActionResult Create([Bind(Include = "Id,BookTitle,BookEdition,BookAuthor1,BookAuthor2,BookCategory,BookPurchasePrice,BookPublisher,BookISBN,BookStatus,BookStorage_Code,BookFormat,ReleaseDate,BFormatId,BCategoryId")] Book book)
        {
            if (ModelState.IsValid)
            {
                db.Books.Add(book);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BCategoryId = new SelectList(db.BCategories, "Id", "BCategoryType", book.BCategoryId);
            ViewBag.BFormatId   = new SelectList(db.BFormats, "Id", "FormatType", book.BFormatId);
            return(View(book));
        }
Ejemplo n.º 17
0
        public int AddBook(Document book)
        {
            try
            {
                _dbContext.Document.Add(book);
                _dbContext.SaveChanges();

                return(1);
            }
            catch
            {
                throw;
            }
        }
        public int AddBook(Book book)
        {
            try
            {
                _dbContext.Book.Add(book);
                _dbContext.SaveChanges();

                return(1);
            }
            catch
            {
                throw;
            }
        }
        public int AddCategory(Categories catgegory)
        {
            try
            {
                _dbContext.Categories.Add(catgegory);
                _dbContext.SaveChanges();

                return(1);
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 20
0
        public void AddBookToCart(int userId, int bookId)
        {
            string cartId   = GetCartId(userId);
            int    quantity = 1;

            CartItems existingCartItem = _dbContext.CartItems.FirstOrDefault(x => x.ProductId == bookId && x.CartId == cartId);

            if (existingCartItem != null)
            {
                existingCartItem.Quantity += 1;
                _dbContext.Entry(existingCartItem).State = EntityState.Modified;
                _dbContext.SaveChanges();
            }
            else
            {
                CartItems cartItems = new CartItems
                {
                    CartId    = cartId,
                    ProductId = bookId,
                    Quantity  = quantity
                };
                _dbContext.CartItems.Add(cartItems);
                _dbContext.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        public string DeleteBook(int id)
        {
            Book book = db.Books.SingleOrDefault(n => n.id == id);

            if (book != null)
            {
                db.Books.Remove(book);
                db.SaveChanges();
                return("Remove Book Success");
            }
            else
            {
                return("Remove Book Fail");
            }
        }
Ejemplo n.º 22
0
 public string DeleteBook(string bookid)
 {
     if (!String.IsNullOrEmpty(bookid))
     {
         try
         {
             using (BookDBContext objContext = new BookDBContext())
             {
                 int bookId = Int32.Parse(bookid);
                 var book   = objContext.book.Find(bookid);
                 objContext.book.Remove(book);
                 objContext.SaveChanges();
                 return("Book record deleted successfully");
             }
         }
         catch (Exception ex)
         {
             return("Book details not found");
         }
     }
     else
     {
         return("Invalid operation");
     }
 }
Ejemplo n.º 23
0
 // Delete book
 public string DeleteBook(string bookId)
 {
     if (!String.IsNullOrEmpty(bookId))
     {
         try
         {
             int _bookId = Int32.Parse(bookId);
             using (BookDBContext contextObj = new BookDBContext())
             {
                 var _book = contextObj.book.Find(_bookId);
                 contextObj.book.Remove(_book);
                 contextObj.SaveChanges();
                 return("Selected book record deleted sucessfully");
             }
         }
         catch (Exception)
         {
             return("Book details not found");
         }
     }
     else
     {
         return("Invalid operation");
     }
 }
Ejemplo n.º 24
0
        public ActionResult Create(Category category, bool?leaf)
        {
            if (ModelState.IsValid)
            {
                category.Id = Guid.NewGuid();
                db.Categories.Add(category);
                // Otherwise EF will try to insert the parent and failed.
                db.Entry(category.Parent).State = EntityState.Unchanged;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            InitializeCategoryViewBag(leaf, null);

            return(View(category));
        }
Ejemplo n.º 25
0
 public ActionResult Create([Bind(Include = "ID,Index,Name,Author,Year,Price,Stock")] S4452232 s4452232)
 {
     if (ModelState.IsValid)
     {
         if (db.S4452232.Any(o => o.ID == s4452232.ID))
         {
             TempData["message"] = "Record already exists.";
             return(RedirectToAction("/Create"));
         }
         db.S4452232.Add(s4452232);
         db.SaveChanges();
         UpdateDatabase();
         SaveBooks(db.S4452232.ToList());
         return(Redirect("/Book/Create"));
     }
     ViewBag.books = db.S4452232.ToList();
     return(View(s4452232));
 }
Ejemplo n.º 26
0
        //Update: Book

        public string UpdateBook(Book book)
        {
            if (book != null)
            {
                int bookId = book.Id;

                Book updatebook = db.Books.Where(b => b.Id == bookId).FirstOrDefault();
                updatebook.Title     = book.Title;
                updatebook.Author    = book.Author;
                updatebook.Publisher = book.Publisher;
                updatebook.Isbn      = book.Isbn;
                db.SaveChanges();

                return("Book Record Updated Successfully");
            }
            else
            {
                return("Invalid Book Record");
            }
        }
Ejemplo n.º 27
0
 protected virtual void UpdateDatabase()
 {
     using (var db = new BookDBContext()) {
         int index = 1;
         foreach (S4452232 book in db.S4452232)
         {
             book.Index = index;
             index++;
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 28
0
        public void ToggleWishlistItem(int userId, int bookId)
        {
            string        wishlistId           = GetWishlistId(userId);
            WishlistItems existingWishlistItem = _dbContext.WishlistItems.FirstOrDefault(x => x.ProductId == bookId && x.WishlistId == wishlistId);

            if (existingWishlistItem != null)
            {
                _dbContext.WishlistItems.Remove(existingWishlistItem);
                _dbContext.SaveChanges();
            }
            else
            {
                WishlistItems wishlistItem = new WishlistItems
                {
                    WishlistId = wishlistId,
                    ProductId  = bookId,
                };
                _dbContext.WishlistItems.Add(wishlistItem);
                _dbContext.SaveChanges();
            }
        }
Ejemplo n.º 29
0
 public int RegisterUser(UserMaster userData)
 {
     try
     {
         userData.UserTypeId = 3;//Normal User
         _dbContext.UserMaster.Add(userData);
         _dbContext.SaveChanges();
         return(1);
     }
     catch
     {
         throw;
     }
 }
Ejemplo n.º 30
0
        public void CreateOrder(int userId, OrdersDto orderDetails)
        {
            try
            {
                StringBuilder orderid = new StringBuilder();
                orderid.Append(CreateRandomNumber(3));
                orderid.Append('-');
                orderid.Append(CreateRandomNumber(6));

                CustomerOrders customerOrder = new CustomerOrders
                {
                    OrderId     = orderid.ToString(),
                    UserId      = userId,
                    DateCreated = DateTime.Now.Date,
                    CartTotal   = orderDetails.CartTotal
                };
                _dbContext.CustomerOrders.Add(customerOrder);
                _dbContext.SaveChanges();

                foreach (CartItemDto order in orderDetails.OrderDetails)
                {
                    CustomerOrderDetails productDetails = new CustomerOrderDetails
                    {
                        OrderId   = orderid.ToString(),
                        ProductId = order.Book.BookId,
                        Quantity  = order.Quantity,
                        Price     = order.Book.Price
                    };
                    _dbContext.CustomerOrderDetails.Add(productDetails);
                    _dbContext.SaveChanges();
                }
            }
            catch
            {
                throw;
            }
        }