示例#1
0
        public ActionResult Index(string search)
        {
            var isbnFiltered = ISBNFilter.Filter(search);
            var books        = new BookRepository().SearchFor(book => book.ISBN.Contains(isbnFiltered) || book.Title.Contains(search)).ToList();
            var model        = Mapper.Map <IEnumerable <Book>, BooksListModel>(books);

            return(View(model));
        }
示例#2
0
        public ActionResult Index(string search)
        {
            var isbnFiltered = ISBNFilter.Filter(search);
            var books        = new BookRepository().SearchFor(book => book.ISBN.Contains(isbnFiltered) || book.Title.Contains(search)).ToList();
            var model        = new BooksListModel
            {
                Books = GetBooksListModels(books)
            };

            return(View(model));
        }
示例#3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string isbn = ISBNFilter.Filter((string)value);

            if (isbn.Length != 13)
            {
                return(new ValidationResult("ISBN has incorrect length (should be 13 digits)", new List <string> {
                    validationContext.MemberName
                }));
            }
            return(ValidationResult.Success);
        }
 public ActionResult Add(BookModel model)
 {
     if (ModelState.IsValid)
     {
         var isbn = ISBNFilter.Filter(model.ISBN);
         new BookRepository().Insert(new Book
         {
             ISBN     = isbn,
             Title    = model.Title,
             AuthorId = model.AuthorId,
         });
         return(RedirectToAction("Index", "Home", new { message = (int)BooksListSuccessMessage.BookAddedSuccesfully }));
     }
     model.IsEditMode = false;
     model.Authors    = GetAuthorsList();
     return(View("Edit", model));
 }
示例#5
0
 public void Should_Filter_The_ISBN_Prefix()
 {
     Assert.AreEqual("9781234567897", ISBNFilter.Filter("ISBN9781234567897"));
 }
示例#6
0
 public void Should_Filter_The_ISBN_Separators()
 {
     Assert.AreEqual("9781234567897", ISBNFilter.Filter("978-1-234-56789-7"));
 }
示例#7
0
 protected override void Configure()
 {
     Mapper.CreateMap <Book, BookModel>()
     .ForMember(model => model.Authors, expression => expression.ResolveUsing(book => GetAuthorsList()))
     .ForMember(model => model.IsEditMode, expression => expression.Ignore());
     Mapper.CreateMap <Book, BookListItemModel>()
     .ForMember(model => model.AuthorFullName, expression => expression.ResolveUsing(book => book.Author.FirstName + " " + book.Author.LastName));
     Mapper.CreateMap <IEnumerable <Book>, BooksListModel>()
     .ForMember(model => model.Books, expression => expression.ResolveUsing(books => books))
     .ForMember(model => model.SuccessMessage, expression => expression.Ignore());
     Mapper.CreateMap <BookModel, Book>()
     .ForMember(book => book.ISBN, expression => expression.ResolveUsing(model => ISBNFilter.Filter(model.ISBN)));
 }