public ActionResult Add(LibraryAdd model, string lib, string type, string bookId, string source)
        {
            Book book = null;

            switch (type)
            {
            case "new": book = model.NewBookModel; break;

            case "goodreads": book = model.GoodreadsBookModel; break;

            case "existing": book = db.Books.FirstOrDefault(bk => bk.Id.ToString() == bookId); break;
            }

            if (!TryValidateModel(book))
            {
                ViewBag.ErrorMsg    = "You have to fill in all fields";
                model.UserLibraries = GetUserLibraries();
                if (source == "search")
                {
                    return(RedirectToAction("Search"));
                }
                else
                {
                    return(View(model));
                }
            }

            if (!AddBookToLibrary(book, lib, model.LenderFirstname, model.LenderLastname))
            {
                ViewBag.ErrorMsg    = "The book you are trying to add is already in this library";
                model.UserLibraries = GetUserLibraries();
                if (source == "search")
                {
                    return(RedirectToAction("Search", new { r = "1" }));
                }
                else
                {
                    return(View(model));
                }
            }
            return(RedirectToAction("Index", new { lib = lib }));
        }
 public ActionResult Add(LibraryAdd model)
 {
     model.UserLibraries = GetUserLibraries();
     return(View(model));
 }