Created
December 1, 2017 10:30
-
-
Save DmitrySikorsky/f84432686834e306ebe43f86b53057c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public IndexViewModel Create() | |
| { | |
| return new IndexViewModel() | |
| { | |
| Categories = this.storage.Categories.ToList().Select( | |
| c => new CategoryViewModelFactory().Create(c) | |
| ), | |
| Articles = this.storage.Articles.OrderBy(a => a.Id).Take(20).ToList().Select( | |
| a => new ArticleViewModelFactory(this.storage).Create(a) | |
| ) | |
| }; | |
| } | |
| public CategoryViewModel Create(Category category) | |
| { | |
| return new CategoryViewModel() | |
| { | |
| Name = category.Name | |
| }; | |
| } | |
| public ArticleViewModel Create(Article article) | |
| { | |
| Category category = this.storage.Categories.Find(article.CategoryId); | |
| Photo photo = this.storage.Photos.FirstOrDefault(ph => ph.ArticleId == article.Id && ph.IsDefault); | |
| return new ArticleViewModel() | |
| { | |
| Category = new CategoryViewModelFactory().Create(category), | |
| Name = article.Name, | |
| Price = article.Price, | |
| Photo = new PhotoViewModelFactory().Create(photo) | |
| }; | |
| } | |
| public PhotoViewModel Create(Photo photo) | |
| { | |
| return new PhotoViewModel() | |
| { | |
| Filename = photo.Filename | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment