public QuestionPosted AllQuestionVotes(QuestionPosted question, VoteEnum vote) { var allQuestionVotes = question.Votes; allQuestionVotes.Append(vote); return(new QuestionPosted(question.QuestionId, question.Title, question.Body, question.Tags, allQuestionVotes.Sum(v => Convert.ToInt32(v)), allQuestionVotes)); }
public QuestionPosted VoteUpdate(QuestionPosted question, VoteEnum vote) { var allvotes = question.AllVotes; allvotes.Append(vote); return(new QuestionPosted(question.QuestionId, question.Question, allvotes.Sum(v => Convert.ToInt32(v)), allvotes)); }
public QuestionCreated VoteUp1(QuestionCreated question, VoteEnum vote) { var vot = question.Vot; vot.Append(vote); return(new QuestionCreated(question.QuefileTi, question.Question, vot.Sum(v => Convert.ToInt32(v)), vot)); }
public async Task VoteMealAsync(string userId, VoteEnum vote, Guid mealId) { var existing = await _dbContext.MealVotes .Where(mv => mv.MealId == mealId) .Where(mv => mv.UserId == userId) .SingleOrDefaultAsync(); if (existing is not null) { //withdraw vote if (vote == existing.Vote) { _dbContext.MealVotes.Remove(existing); return; } //If different, then apply change existing.Vote = vote; return; } await _dbContext.MealVotes.AddAsync(new MealVote { MealId = mealId, UserId = userId, Vote = vote }); }
public QuestionPosted UpdateVote(QuestionPosted question, VoteEnum vote) { var votes = question.AllVotes; votes.Append(vote); return(new QuestionPosted(question.Title, question.Tags, votes.Sum(v => Convert.ToInt32(v)), votes)); }
public QuestionAdded Update(QuestionAdded result, VoteEnum newVote) //update votes counter on every new vote added to the list { var totalvotes = result.TotalVotes.ToList(); //get current list of votes totalvotes.Add(newVote); //add current vote to the list return(new QuestionAdded(result.Id, result.Title, result.Text, result.Tags, totalvotes.Sum(nrOfVotes => Convert.ToInt32(nrOfVotes)), totalvotes)); //update question data }
public static KeyValuePair <VoteEnum, PollMode>[] GetPollModes(this VoteEnum vote) => vote .GetFlags() .Select(v => KeyValuePair.Create(v, v.GetPollMode())).Where(_ => _.Value != null) .DefaultIfEmpty(KeyValuePair.Create(vote, vote.GetPollMode())).Where(_ => _.Value != null) .Select(pair => KeyValuePair.Create(pair.Key, pair.Value.Value)) .OrderBy(pair => pair.Key.GetAttributes()?.Get <DisplayAttribute>()?.GetOrder()) .ToArray();
//adds new vote to AllVotes list and then changes the score public QuestionPosted Update(QuestionPosted quest, VoteEnum vote) { var lines = quest.AllVotes.ToList(); lines.Add(vote); return(new QuestionPosted(quest.QuestionId, quest.Title, lines, lines.Sum())); }
public VoteGrouping(VoteEnum flag, int order, int displayOrder, string singular, string plural) { Order = order; DisplayOrder = displayOrder; Singular = singular; Plural = plural; Flag = flag; NestedGrouping = null; }
public QuestionPosted UpdateVote(QuestionPosted question, VoteEnum vote) { var votes = question.AllVotes; votes.Append(vote); //the score obtained from the votes must correspond to the sum of all the votes of the individual return(new QuestionPosted(question.Title, question.Tags, votes.Sum(v => Convert.ToInt32(v)), votes)); }
public static IEnumerable <VoteEnum> GetFlags(VoteEnum vote) { var processed = VoteEnum.None; foreach (var possibleVote in Enums.GetValues <VoteEnum>(EnumMemberSelection.DisplayOrder | EnumMemberSelection.Distinct)) { if (vote.HasAllFlags(possibleVote) && !processed.HasAllFlags(possibleVote)) { processed |= possibleVote; yield return(possibleVote); } } }
public static TextBuilder Format(this VoteEnum vote, TextBuilder builder) => GetFlags(vote).Aggregate(builder, (b, v) => b.Sanitize(v.AsString(EnumFormat.DisplayName)));
public static string Description(this VoteEnum vote) => (vote.RemoveFlags(VoteEnum.Modifiers) is var voteWithoutModifiers && voteWithoutModifiers.HasAnyFlags() ?
// TODO: check for overflow public static VoteEnum IncreaseVotesCount(this VoteEnum vote, int diff) => vote .RemoveFlags(VoteEnum.Plus) .CombineFlags((VoteEnum)((((int)vote.CommonFlags(VoteEnum.Plus) >> FirstPlusBit) + diff) << FirstPlusBit));
public static PollMode?GetPollMode(this VoteEnum vote) => ourVoteToPollMode.TryGetValue(vote, out var pollMode) ? pollMode : default;
public void AddVote(VoteEnum vote) { Votes.Add(vote); }
public AskQuestionResult.QuestionAdded Update(AskQuestionResult.QuestionAdded question, VoteEnum vote) { var votes = question.Votes.ToList(); votes.Add(vote); return(new AskQuestionResult.QuestionAdded(question.Id, question.Title, question.Text, question.Tags, votes.Sum(score => Convert.ToInt32(score)), votes)); }
public VoteGrouping(VoteEnum flag, int order, int displayOrder, string singular, string plural, params VoteGrouping[] nestedGrouping) : this(flag, order, displayOrder, singular, plural) { NestedGrouping = nestedGrouping; }
public ActionResult Vote(int postId, VoteEnum type) { if (cService.GetPost(postId).UserId == _currentUserId) { return(Json(new { result = "", message = "Bạn không thể tự bình chọn cho chính mình." })); } Vote vote = new Vote(); vote.PostId = postId; vote.VotedDate = DateTime.Now; vote.Type = type; vote.UserId = _currentUserId; bool check = qService.Vote(vote); if (check && type == VoteEnum.VoteUp) { if (vote.Post.UserId != _currentUserId) { //new Thread(() => //{ Question question; NotificationSettingEnum notiType; int userId; if (vote.Post is Question) { question = qService.GetQuestion(vote.PostId); notiType = NotificationSettingEnum.VotedQuestion; userId = question.UserId; } else { question = qService.GetQuestion(((Answer)vote.Post).QuestionId); notiType = NotificationSettingEnum.VotedAnswer; userId = vote.Post.UserId; } Notification notification = new Notification(); notification.AuthorId = _currentUserId; notification.CreatedDate = DateTime.Now; notification.Content = question.Title; notification.Seen = false; notification.Type = notiType; notification.UserId = userId; notification.Link = Url.Action("Detail", "Question", new { id = question.Id }); cService.AddNotification(notification); using (RealTimeService rService = new RealTimeService(new CPMathHubModelContainer(), notification.UserId)) { IEnumerable <string> connectionIds = RealTimeHub.Connections.GetConnections(notification.UserId); foreach (string conId in connectionIds) { _hub.Clients.Client(conId).notifyNewActivity(rService.CountNewActivityNotification()); } } //} //).Start(); } return(Json(new { result = "up" })); } else if (check && type == VoteEnum.VoteDown) { return(Json(new { result = "down" })); } else { return(Json(new { result = "", message = "Bạn không thể bình chọn nhiều hơn 1 lần." })); } }