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)); }
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)); }
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)); }
public void Should_Filter_The_ISBN_Prefix() { Assert.AreEqual("9781234567897", ISBNFilter.Filter("ISBN9781234567897")); }
public void Should_Filter_The_ISBN_Separators() { Assert.AreEqual("9781234567897", ISBNFilter.Filter("978-1-234-56789-7")); }
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))); }