예제 #1
0
        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));
        }
예제 #3
0
파일: VotUp.cs 프로젝트: LungRaul/PSSC-2020
        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));
        }
예제 #4
0
        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
            });
        }
예제 #5
0
        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));
        }
예제 #6
0
        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
        }
예제 #7
0
 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();
예제 #8
0
            //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()));
            }
예제 #9
0
 public VoteGrouping(VoteEnum flag, int order, int displayOrder, string singular, string plural)
 {
     Order          = order;
     DisplayOrder   = displayOrder;
     Singular       = singular;
     Plural         = plural;
     Flag           = flag;
     NestedGrouping = null;
 }
예제 #10
0
        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));
        }
예제 #11
0
        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);
                }
            }
        }
예제 #12
0
 public static TextBuilder Format(this VoteEnum vote, TextBuilder builder) =>
 GetFlags(vote).Aggregate(builder, (b, v) => b.Sanitize(v.AsString(EnumFormat.DisplayName)));
예제 #13
0
 public static string Description(this VoteEnum vote) =>
 (vote.RemoveFlags(VoteEnum.Modifiers) is var voteWithoutModifiers && voteWithoutModifiers.HasAnyFlags() ?
예제 #14
0
 // 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));
예제 #15
0
 public static PollMode?GetPollMode(this VoteEnum vote) =>
 ourVoteToPollMode.TryGetValue(vote, out var pollMode) ? pollMode : default;
예제 #16
0
 public void AddVote(VoteEnum vote)
 {
     Votes.Add(vote);
 }
예제 #17
0
        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));
        }
예제 #18
0
 public VoteGrouping(VoteEnum flag, int order, int displayOrder, string singular, string plural, params VoteGrouping[] nestedGrouping) :
     this(flag, order, displayOrder, singular, plural)
 {
     NestedGrouping = nestedGrouping;
 }
예제 #19
0
        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." }));
            }
        }