protected int GetLikes(Question question) { if (question.Votes.Count > 0) { return question.Votes.Sum(l => l.Value); } return 0; }
protected void ButtonAddTopic_Click(object sender, EventArgs e) { var userId = HttpContext.Current.User.Identity.GetUserId(); var val = this.DropDownListTopicCategories.SelectedValue; var txt = this.DropDownListTopicCategories.SelectedItem; var ind = this.DropDownListTopicCategories.SelectedIndex; var question = new Question { Title = this.TextBoxTitle.Text, Content = this.TextBoxContent.Text, UserId = userId, CategoryId = int.Parse(this.Request.Params["id"]) }; this.Data.Questions.Add(question); this.Data.SaveChanges(); }
protected int GetCurrentUserVote(Question question) { string userId = User.Identity.GetUserId(); Vote vote= question.Votes.FirstOrDefault(l => l.UserId == userId); if (vote == null) { return 0; } return vote.Value; }