protected int GetLikesValue(ArticleProjection item) { var article = this.context.Articles.Find(item.ArticleId); int likesCount = article.Likes.Count(l => l.Value == true); int hatesCount = article.Likes.Count(l => l.Value == false); return likesCount - hatesCount; }
protected bool? GetUserVote(ArticleProjection item) { var article = this.context.Articles.Find(item.ArticleId); string userId = this.userIdProvider.GetUserId(); var like = article.Likes.FirstOrDefault(l => l.UserId == userId); if (like == null) { return null; } return like.Value; }
public void ListViewArticles_InsertItem() { var articleProjection = new ArticleProjection(); this.TryUpdateModel(articleProjection); var categoryId = int.Parse(articleProjection.CategoryName); if (string.IsNullOrEmpty(articleProjection.Title) || string.IsNullOrEmpty(articleProjection.Content)) { ErrorSuccessNotifier.AddMessage(new NotificationMessage() { Text = "Cannot create article with emptry title/content.", AutoHide = false, Type = MessageType.Warning }); return; } var article = new Article() { Title = articleProjection.Title, Content = articleProjection.Content, AuthorId = this.userIdProvider.GetUserId(), DateCreated = DateTime.Now, CategoryId = categoryId }; if (this.ModelState.IsValid) { this.context.Articles.Add(article); this.TryUpdateOrShowMessage(new NotificationMessage() { Text = "Article was created successfully.", AutoHide = false, Type = MessageType.Success }); } }