예제 #1
0
        public void validateEditedBook(BookService.Book book)
        {
            if (string.IsNullOrEmpty(book.Author))
            {
                ModelState.AddModelError("Author", "Please enter the name of the Author");
            }
            if (string.IsNullOrEmpty(book.Title))
            {
                ModelState.AddModelError("Title", "Please enter the name of the book");
            }
            if (book.Genre == null)
            {
                ModelState.AddModelError("Genre", "Please enter the genre of the book");
            }
            if (book.Price == 0)
            {
                ModelState.AddModelError("Price", "Please enter the price of the book");
            }
            if (string.IsNullOrEmpty(book.Description))
            {
                book.Description = "";
            }

            ModelState.Remove("PublishDate");
            ModelState.Remove("Description");
        }
예제 #2
0
        /*
         * public static PersonService.Person PersonToServiceObject(LibraryObjects.Person personFromLibrary)
         * {
         *  return main(personFromLibrary.Id, personFromLibrary.Name, personFromLibrary.Surname, personFromLibrary.Password, personFromLibrary.BirthDate, personFromLibrary.PhoneNumber, personFromLibrary.Email);
         * }
         * /*
         * public static LibraryObjects.Person PersonToServiceObject(PersonService.Person personFromPersonService)
         * {
         *  return new LibraryObjects.Person(personFromPersonService.Id, personFromPersonService.Name, personFromPersonService.Surname, personFromPersonService.Password, personFromPersonService.BirthDate, personFromPersonService.PhoneNumber, personFromPersonService.Email);
         * }
         * public static BookService.Person PersonToServiceObject(LibraryObjects.Person personFromBookService)
         * {
         *  return new BookService.Person(personFromBookService.Id, personFromBookService.Name, personFromBookService.Surname, personFromBookService.Password, personFromBookService.BirthDate, personFromBookService.PhoneNumber, personFromBookService.Email);
         * }
         */

        /*
         * public delegate LibraryObjects.Book Delegate(BookService.Book bookFromService);
         * public static Delegate bookToLibraryObjectDel = new Delegate(BookToLibraryObject);
         */

        public static LibraryObjects.Book BookToLibraryObject(BookService.Book bookFromBookService)
        {
            if (bookFromBookService == null)
            {
                return(null);
            }

            return(new LibraryObjects.Book(bookFromBookService.Id, bookFromBookService.Name, bookFromBookService.Author, bookFromBookService.Publisher, bookFromBookService.Year, bookFromBookService.Pages, bookFromBookService.Isbn, bookFromBookService.Code, bookFromBookService.IsTaken, bookFromBookService.ReaderId, bookFromBookService.TakenAt, bookFromBookService.ReturnAt));
        }
예제 #3
0
        public ActionResult SaveBook(BookService.Book book)
        {
            validateEditedBook(book);                                                            //Validate edited book

            if (book != null && ModelState.IsValid)
            {
                if (string.IsNullOrEmpty(book.ID))
                {
                    bookServ.NewBook(book);
                }
                else
                {
                    bookServ.EditBook(book);
                }

                return(RedirectToAction("Index", "Book"));
            }

            return(View("BookForm", book));
        }
예제 #4
0
 public ActionResult DeleteBook(BookService.Book book)
 {
     bookServ.DeleteBook(book);
     return(RedirectToAction("Index", "Book"));
 }