예제 #1
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Language language = dao.Find(id);

            if (language == null)
            {
                return(HttpNotFound());
            }
            return(View(language));
        }
예제 #2
0
        public ActionResult Create(Book book, string[] selectedAuthors)
        {
            PopulateLanguagesDropDownList();
            PopulateGenresDropDownList();
            PopulateBookAuthors(book);
            try
            {
                if (ModelState.IsValid)
                {
                    Language l = languageDAO.Find(book.LanguageID);
                    Genre    g;
                    if (book.GenreID == -1)
                    {
                        g      = new Genre();
                        g.Id   = -1;
                        g.Name = "";
                    }
                    else
                    {
                        g = genreDAO.Find(book.GenreID);
                    }
                    book.Id       = dao.CurrentID() + 1;
                    book.Language = l;
                    book.Genre    = g;
                    UpdateBookAuthors(selectedAuthors, book);
                    if (book.Authors.Count == 0)
                    {
                        ModelState.AddModelError("", "At least one author should be selected");
                        return(View(book));
                    }
                    dao.Create(book);
                    return(RedirectToAction("Index"));
                }
            }
            catch
            {
                ModelState.AddModelError("", "Unable to save changes.");
            }

            return(View(book));
        }