Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created December 1, 2017 10:30
Show Gist options
  • Save DmitrySikorsky/f84432686834e306ebe43f86b53057c3 to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/f84432686834e306ebe43f86b53057c3 to your computer and use it in GitHub Desktop.
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