public ActionResult AddBook(BookModel model) { // Redirect is the user isn't an admin if (!IdentityModel.CurrentUserAdmin) { return RedirectToAction("Index", "Home"); } ViewBag.Error = String.Empty; model = BindModel(model); if (!ModelState.IsValid) return View(model); if (model.AddBook()) { ViewBag.Error = "Het boek is toegevoegd!"; return View(model); } ViewBag.Error = "Het boek is niet toegevoegd, probeer het later nog eens!"; return View(model); }
private static BookModel BindModel(BookModel model) { var genreTypes = Enum.GetValues(typeof (BookModel.BookGenres)).Cast<BookModel.BookGenres>(); model.Genres = from genre in genreTypes select new SelectListItem { Text = BookModel.DictGenre[genre], Value = ((int) genre).ToString(CultureInfo.InvariantCulture) }; var floorTypes = Enum.GetValues(typeof (BookModel.BookFloors)).Cast<BookModel.BookFloors>(); model.Floors = from floor in floorTypes select new SelectListItem { Text = BookModel.DictFloors[floor] + " verdieping", Value = ((int) floor).ToString(CultureInfo.InvariantCulture) }; var rackTypes = Enum.GetValues(typeof (BookModel.BookRacks)).Cast<BookModel.BookRacks>(); model.Racks = from rack in rackTypes select new SelectListItem { Text = BookModel.DictRacks[rack] + " rek", Value = ((int) rack).ToString(CultureInfo.InvariantCulture) }; return model; }