public PublicationPreviewViewModel(List<Article> articles, MyBlogRepository rep, string tag) { this.Articles = new List<Article>(); int tagId = rep.Tags.Where(x => x.TagName == tag).Select(x => x.Id).FirstOrDefault(); List<int> articlesId = rep.GetArticlesToTags(tagId); foreach(int articleId in articlesId) { this.Articles.Add(rep.Articles.Find(x => x.Id == articleId)); } }
public NewPublicationViewModel(MyBlogRepository repository, int id) { this.Id = id; var publication = repository.Articles.Find(x => x.Id == id); this.Title = publication.ArticleTitle; this.ArticleText = publication.ArticleText; var selectedTagsId = repository.GetTagsIdToArticle(id); this.Tags = repository.Tags.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.TagName }).ToList(); foreach(int curSelTagId in selectedTagsId) { for (int i = 0; i < this.Tags.Count; i++ ) { if (curSelTagId.ToString() == this.Tags[i].Value) { this.Tags[i].Selected = true; } } } }
public AboutSelfFormViewModel(MyBlogRepository repository) { AboutSelf = new AboutSelf(); genderText = new List<String> { "мужской", "женский" }; hobbyText = new List<String> { "спорт", "видеоигры", "коллекционирование", "йога" }; }
public void FillTags(MyBlogRepository repository) { this.Tags = repository.Tags.Select(x => new SelectListItem() { Value = x.Id.ToString(), Text = x.TagName }).ToList(); }
public NewPublicationViewModel(MyBlogRepository repository) { FillTags(repository); }