Exemplo n.º 1
0
        public async Task <Unit> Handle(VoteOnAnswerCommand command, CancellationToken cancellationToken)
        {
            var request = await _context.Requests.Include(r => r.Answers)
                          .FirstOrDefaultAsync(s => s.Id == command.RequestId, cancellationToken);

            CheckVoteOnAnswerCommandForNull(command, request);

            var answerToSave = new AnswerVote
            {
                AnswerId = command.RequestId,
                UserId   = command.UserId,
                Like     = command.Like
            };

            await _context.AnswerVotes.AddAsync(answerToSave, cancellationToken);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
 public ActionResult SaveAnswerVote(object answerId, int userId, bool vote)
 {
     using (SOFModel dc = new SOFModel())
     {
         string[] array = (string[])answerId;
         int      aID   = Convert.ToInt32(array[0]);
         try
         {
             AnswerVote av;
             if (dc.AnswerVotes.Where(x => x.AnswerId == aID && x.UserId == userId).FirstOrDefault() != null)
             {
                 av      = dc.AnswerVotes.Where(x => x.AnswerId == aID && x.UserId == userId).First();
                 av.Vote = vote;
             }
             else
             {
                 av          = new AnswerVote();
                 av.AnswerId = aID;
                 av.UserId   = userId;
                 av.Vote     = vote;
                 dc.AnswerVotes.Add(av);
             }
             dc.SaveChanges();
         }
         catch (Exception e)
         {
             string a = e.Message;
         }
         int count = 0;
         foreach (AnswerVote item in dc.AnswerVotes.Where(x => x.AnswerId == aID).ToList())
         {
             count += item.Vote == true ? 1 : -1;
         }
         return(Json(count));
     }
 }
Exemplo n.º 3
0
 public static AnswerVote PositiveVote(User user)
 {
     var vote = new AnswerVote(user, PositiveValue);
     return vote;
 }
        public static string IsAnsDownVoteInsert(AnswerVote downVote)
        {
            int rowAffected = AnswerGetaway.InsertAnsDownVote(downVote);

            return((rowAffected > 0) ? "true" : "false");
        }