Example #1
0
        public ActionResult Create(Book book)
        {
            if (book.CategoryId == 0)
            {
                ModelState.AddModelError("CategoryId","Please Select Category.");
            }

            if (ModelState.IsValid)
            {
                book.UserId = WebSecurity.CurrentUserId;
                db.Books.Add(book);
                db.SaveChanges();
                Information(SAVED);
                return RedirectToAction("Index");
            }
            ViewBag.CategoryId = new SelectList(GetCategories().OrderBy(b => b.Name),"Id","Name",book.CategoryId);
            return View(book);
        }
Example #2
0
 public ActionResult Edit(Book book)
 {
     if (ModelState.IsValid)
     {
         book.UserId = WebSecurity.CurrentUserId;
         db.Entry(book).State = EntityState.Modified;
         db.SaveChanges();
         Information(UPDATED);
         return RedirectToAction("Index");
     }
     ViewBag.Category = new SelectList(db.Categories.OrderBy(b => b.Name),"Id","Name",book.CategoryId);
     return View(book);
 }