/// <summary> /// Static <c>Map</c> method maps a <see cref="Core.Model.LibraryBook"/> class to a /// <see cref="THLibrary.DataModel.BookViewModel"/> class. /// </summary> /// <param name="book">The LibraryBook instance.</param> /// <returns>The BookViewModel instance.</returns> public static BookViewModel Map(LibraryBook book) { // Instantiate directly as this is only even used within this UI. // TODO: (If Time) refactor this to an abstract factory to create the BookViewModel var bookVM = new BookViewModel() { Author = book.Author, Title = book.Title, ISBN = book.ISBN, Keywords = new ObservableCollection<string>(book.KeyWords), Synopsis = book.Synopsis }; if (book.ImagePath==string.Empty) bookVM.SetImage("Assets/Logo.png"); // TODO: update to correct image file, default for now. else bookVM.SetImage(string.Format("Assets/{0}", book.ImagePath)); return bookVM; }
/// <summary> /// Method <c>SetUpTestData</c> load the view model with temporary data. /// </summary> private void SetUpTestData() { // Set up some book data; BookViewModel book = new BookViewModel() { UniqueId = "Book 1", Author = "Adam Freeman", Title = "Pro ASP.NET MVC 3 Framework", ISBN = "123456789", Synopsis = "A damn good book", Keywords = new ObservableCollection<string>() { ".NET", "MVC" } }; book.SetImage("Assets/Logo.png"); this.AllBooks.Add(book); book = new BookViewModel() { UniqueId = "Book 2", Author = "Scott Millett", Title = "ASP.NET Design Patterns", ISBN = "234567890", Synopsis = "Excellent and extremely well documented examples", Keywords = new ObservableCollection<string>() { ".NET", "MVC", "Patterns" } }; book.SetImage("Assets/Logo.png"); this.AllBooks.Add(book); book = new BookViewModel() { UniqueId = "Book 3", Author = "Mark Seemann", Title = "Dependency Injection in .NET", ISBN = "345678901", Synopsis = "All you really need to know about DI, except MVC4", Keywords = new ObservableCollection<string>() { ".NET", "DI", "Patterns" } }; book.SetImage("Assets/Logo.png"); this.AllBooks.Add(book); // Set up some previous searches SearchViewModel search = new SearchViewModel() { UniqueId = "Search 1", SearchDate = "01/12/2012", SearchString = ".NET|MVC", Type = "Keyword" }; this.AllSearches.Add(search); search = new SearchViewModel() { UniqueId = "Search 2", SearchDate = "02/12/2012", SearchString = "Adam Freeman", Type = "Author" }; this.AllSearches.Add(search); search = new SearchViewModel() { UniqueId = "Search 3", SearchDate = "01/12/2012", SearchString = "Pro ASP.NET MVC 3 Framework", Type = "Title" }; this.AllSearches.Add(search); // Set up the search Types and corresponding values SearchTypesViewModel type = new SearchTypesViewModel() { Type = "Select a Type...", Values = new ObservableCollection<string>() { " " } }; this.CurrentSearch.SearchTypes.Add(type); this.SearchTypes.Add(type); type = new SearchTypesViewModel() { Type = "Author", Values = new ObservableCollection<string>() { "Select an Author..", "Adam Freeman", "Scott Millett", "Mark Seemann" } }; this.CurrentSearch.SearchTypes.Add(type); this.SearchTypes.Add(type); type = new SearchTypesViewModel() { Type = "Keyword", Values = new ObservableCollection<string>() { "Select a Keyword..", ".NET", "MVC", "Patterns", "DI" } }; this.CurrentSearch.SearchTypes.Add(type); this.SearchTypes.Add(type); type = new SearchTypesViewModel() { Type = "ISBN", Values = new ObservableCollection<string>() { "Select an Isbn..", "123456789", "234567890", "345678901" } }; this.CurrentSearch.SearchTypes.Add(type); this.SearchTypes.Add(type); type = new SearchTypesViewModel() { Type = "Title", Values = new ObservableCollection<string>() { "Select a Title..", "Pro ASP.NET MVC 3 Framework", "ASP.NET Design Patterns", "Dependency Injection in .NET" } }; this.CurrentSearch.SearchTypes.Add(type); this.SearchTypes.Add(type); // Set the curent search as the first one this.CurrentSearch.UniqueId = this.AllSearches[0].UniqueId; this.CurrentSearch.Type = this.AllSearches[0].Type; this.CurrentSearch.SearchString = this.AllSearches[0].SearchString; this.CurrentSearch.SearchDate = this.AllSearches[0].SearchDate; this.CurrentSearch.SelectedTypeIndex = 1; this.CurrentSearch.SelectedTypeValueIndex = -1; // Reset so the next update shows this.CurrentSearch.SelectedTypeValueIndex = 0; // Update the value drop down. }