public ActionResult AddBooks(Book book) { //Get cookie, check if user is logined if (HttpContext.Request.Cookies.AllKeys.Contains("user")) { var cookievalue = Request.Cookies["user"].Value.ToString(); //Check if the logined user is the Admin, if i used identetiy i would have checked on roles here if (cookievalue == "*****@*****.**") { ViewBag.Message = "Admin page to add new books!"; if (ModelState.IsValid) { BookAdder.CreateBook(book.book_name, book.book_genre, book.book_year, book.book_description); return(RedirectToAction("Index")); } return(View()); } else { return(RedirectToAction("Index")); } } else { return(RedirectToAction("Index")); } }
public ActionResult Books() { var books = BookAdder.LoadBooks(); var viewModel = new LibraticaViewModel { Books = books.ToList(), }; return(View(viewModel)); }
/// <summary> /// Create a new add book controller. /// </summary> /// <param name="bookAdder">The book adder to use.</param> public AddBookController(BookAdder bookAdder) { this.bookAdder = bookAdder; }