public ActionResult CreateBook()
        {
            AuthorizeAndRedirect();
            BookAuthorClassification bookAuthorClassification = _BookAuthorClassificationManager.Setup();

            return(View("CreateBook", bookAuthorClassification));
        }
        public ActionResult EditBook(string id)
        {
            AuthorizeAndRedirect();
            BookAuthorClassification bookAuthorClassification = _BookAuthorClassificationManager.Setup();

            bookAuthorClassification.Book = _Manager.GetBookFromIsbn(id);
            return(View("EditBook", bookAuthorClassification));
        }
        public BookAuthorClassification Setup()
        {
            ClassificationManager    classificationManager    = new ClassificationManager();
            AuthorManager            authorManager            = new AuthorManager();
            BookAuthorClassification bookAuthorClassification = new BookAuthorClassification
            {
                Authors         = authorManager.GetAllAuthorsToList(),
                Classifications = classificationManager.GetAllClassifications()
            };

            return(bookAuthorClassification);
        }
        public ActionResult EditBook(BookAuthorClassification bookAuthorClassification, string[] authorChecklist, int classificationRadio)
        {
            AuthorizeAndRedirect();
            Tuple <Book, BookValidation> bookTuple = _Manager.EditBook(bookAuthorClassification, authorChecklist, classificationRadio);

            if (bookTuple.Item2.IsValid)
            {
                ModelState.Clear();
                return(RedirectToAction("ListBookDetails", "Book", new { id = bookTuple.Item1.ISBN }));
            }
            ValidationMessages.ConvertCodeToMsg(ModelState, bookTuple.Item2.ErrorDict);
            return(RedirectToAction("EditBook", "BookAuthorClassification", new { id = bookAuthorClassification.Book.ISBN }));
        }
Exemple #5
0
        public Tuple <Book, BookValidation> CreateBook(BookAuthorClassification bookAuthorClassification, string[] authorChecklist, int?classificationRadio)
        {
            AuthorManager         authorManager         = new AuthorManager();
            ClassificationManager classificationManager = new ClassificationManager();
            Book book = bookAuthorClassification.Book;

            book.Authors = new List <Author>();
            if (classificationRadio == null) //Add the Generic classification if no classification was selected in in the form.
            {
                book.Classification = classificationManager.AddGenericClassification();
                book.SignId         = book.Classification.SignId;
            }
            else
            {
                book.Classification = classificationManager.GetClassificationFromID(Convert.ToInt32(classificationRadio));
                book.SignId         = book.Classification.SignId;
            }
            if (authorChecklist != null)
            {
                foreach (string aId in authorChecklist)
                {
                    book.Authors.Add(authorManager.GetAuthorFromID(Convert.ToInt32(aId)));
                }
            }
            BookValidation validation = new BookValidation(book);

            if (_Repo.DoesBookExist(book.ISBN))
            {
                validation.DoesAlreadyExistOnServer(nameof(book.ISBN));
            }
            else if (validation.IsValid)
            {
                BOOK repoBOOK = _Repo.CreateBook(Mapper.Map <Book, BOOK>(book));
                if (repoBOOK == null)
                {
                    validation.FailedToCreateBook(nameof(book.Title));
                }
                else
                {
                    Book newBook = Mapper.Map <Book>(repoBOOK);
                    if (newBook != null)
                    {
                        return(new Tuple <Book, BookValidation>(newBook, validation));
                    }
                    validation.FailedToCreateBook(nameof(book.Title));
                }
            }
            return(new Tuple <Book, BookValidation>(null, validation));
        }