public async Task SendReactionAsync(ReactionDto reactionDto) { var game = await gameRepository.GetAsync(reactionDto.GameId); if (game.DrawerPlayerId != reactionDto.UserId) { await Clients.Caller.SendAsync("Error", new ErrorMessage { Id = "send-reaction-error", Message = "Only selected drawer can draw on canvas" }); return; } var message = await chatMessageRepository.GetAsync(reactionDto.MessageId); var messageSender = await userRepository.GetAsync(message.UserId); if (reactionDto.Reaction == Reaction.Warm && message.Reaction == Reaction.None) { if (!game.PointsByPlayerId.ContainsKey(message.UserId)) { game.PointsByPlayerId[message.UserId] = 0; } if (game.PointsByPlayerId[message.UserId] <= 48) { game.PointsByPlayerId[message.UserId] += 2; messageSender.Points += 2; await userRepository.MergeAsync(messageSender); } await gameRepository.MergeAsync(game); } if (message.Reaction == Reaction.Correct) { var passedTime = (DateTime.UtcNow - game.StartTime.Value).Seconds; var timeLeft = game.GameTimeInSeconds - passedTime; game.PointsByPlayerId[game.DrawerPlayerId] = timeLeft; if (!game.PointsByPlayerId.ContainsKey(message.UserId)) { game.PointsByPlayerId[message.UserId] = 0; } game.PointsByPlayerId[message.UserId] += 50; messageSender.Points += 50; await userRepository.MergeAsync(messageSender); game.FinishTime = DateTime.UtcNow; game.Status = GameStatus.Finished; await gameRepository.MergeAsync(game); } message.Reaction = reactionDto.Reaction; await chatMessageRepository.MergeAsync(message); var groupName = reactionDto.GameId.ToString(); var reactionToSendDto = mapper.Map <ReactionToSendDto>(reactionDto); await Clients.Group(groupName).SendAsync("SendReaction", reactionToSendDto); }
// POST: api/Reaction public bool Post(ReactionDto reaction) { if (Session.Session.Validate(reaction.sessionId)) { ReactionBll reactionBll = new ReactionBll(); return(reactionBll.AddReaction(reaction)); } return(false); }
public async Task <IActionResult> GetAsync([FromRoute] Guid reactionId) { // Act. var result = await _reactionService.GetAsync(reactionId); // Map. ReactionDto output = _mapper.Map <ReactionDto>(result); // Return. return(Ok(output)); }
/// <summary> /// Adds the reaction. /// </summary> /// <param name="reaction">The reaction.</param> /// <returns></returns> public bool AddReaction(ReactionDto reaction) { var postReaction = glitterDb.PostReactions.Where(i => i.Post_id == reaction.Post_id && i.user_id == reaction.user_id).SingleOrDefault(); if (postReaction != null) { if (reaction.Reaction == postReaction.Reaction) { var post = glitterDb.Posts.Where(i => i.id == reaction.Post_id).SingleOrDefault(); try { if (reaction.Reaction) { post.Like_count = post.Like_count - 1; } else { post.dislike_count = post.dislike_count - 1; } } catch (NullReferenceException) { } glitterDb.PostReactions.Remove(postReaction); glitterDb.SaveChanges(); } else if (postReaction.Reaction != reaction.Reaction) { postReaction.Reaction = reaction.Reaction; updateReactionCount(reaction.Post_id, reaction.Reaction); glitterDb.SaveChanges(); } return(true); } postReaction = new PostReaction(); postReaction.Post_id = reaction.Post_id; postReaction.user_id = reaction.user_id; postReaction.Reaction = reaction.Reaction; glitterDb.PostReactions.Add(postReaction); var post1 = glitterDb.Posts.Where(i => i.id == reaction.Post_id).SingleOrDefault(); if (postReaction.Reaction) { post1.Like_count = post1.Like_count + 1; } else { post1.dislike_count = post1.dislike_count + 1; } glitterDb.SaveChanges(); // updateReactionCount(reaction.Post_id, reaction.Reaction); return(true); }
public async Task <IActionResult> Update([FromRoute] Guid reactionId, [FromBody] ReactionDto input) { // Map. Reaction reaction = _mapper.Map <Reaction>(input); reaction.Id = reactionId; // Act. await _reactionService.UpdateAsync(reaction); // Return. return(NoContent()); }
public ReactionAPIPayload(ReactionDto reaction) { _reaction = reaction; }
public IActionResult PostReaction([FromServices] DispatchManager dispatchManager, [FromServices] Core.AppContext appContext, [FromBody] ReactionDto input) { // Act. var postReactionContext = new PostReactionContext { IsPrivate = input.IsPrivate, ReactionId = input.Id, TargetVlogId = input.TargetVlogId, UserId = appContext.UserId, }; dispatchManager.Dispatch <PostReactionBackgroundTask>(postReactionContext); // Return. return(NoContent()); }
public bool AddReaction(ReactionDto reaction) { operationOnReaction = new ReactionOperation(); return(operationOnReaction.AddReaction(reaction)); }