Exemplo n.º 1
0
        public void AddOrUpdate(ReactionModel reaction)
        {
            string sql = Queries.updateReaction;

            sql = FormatAddOrUpdateQuery(sql, reaction);
            _data.SaveData(sql, reaction);
        }
Exemplo n.º 2
0
        public SavePostResponseModel RemoveVote(ReactionModel reaction)
        {
            var client  = new RestClient(ServerAddress);
            var request = new RestRequest("Reactions/RemoveReaction", Method.POST);

            request.AddParameter("SlackUserId", reaction.User);
            request.AddParameter("Reaction", reaction.Reaction);
            request.AddParameter("MessageTimeStamp", reaction.Item.TS);

            IRestResponse response = client.Execute(request);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                return new SavePostResponseModel {
                           StatusCode = response.StatusCode
                }
            }
            ;

            //If there are errors
            return(new SavePostResponseModel
            {
                StatusCode = response.StatusCode,
                ErrorMessage = response.Content
            });
        }
Exemplo n.º 3
0
        private string GetAllReactionsQuery(ReactionModel reaction)
        {
            string additionalConditions = "";
            var    ColumnsAndParams     = GetColumnsAndParams(reaction);
            var    columns    = ColumnsAndParams[0];
            var    parameters = ColumnsAndParams[1];

            for (int i = 0; i < columns.Count; i++)
            {
                string value;
                if (columns[i] == "text_trigger" || columns[i] == "text_response")
                {
                    value = $"instr({columns[i]}, {parameters[i]})";
                }
                else
                {
                    value = $"{columns[i]} = {parameters[i]}";
                }
                additionalConditions += $"and {value} ";
            }

            string sql = Queries.getAllReactions;

            sql = string.Format(sql, additionalConditions);
            return(sql);
        }
Exemplo n.º 4
0
        public async Task IsRemovingUserTweetReactionInToggle()
        {
            this.populate();

            List <UserTweetReactionModel> models = _dbContext.UserTweetReaction.ToList();

            Assert.AreEqual(0, models.Count);

            AppUser       user     = _dbContext.Users.FirstOrDefault(u => u.Nickname == "marcow");
            TweetModel    tweet    = _dbContext.Tweet.FirstOrDefault(t => t.UserId == user.Id);
            ReactionModel reaction = _dbContext.Reaction.FirstOrDefault(r => r.Name == "Star");

            UserTweetReaction userTweetReaction = new UserTweetReaction
            {
                UserId = user.Id, TweetId = tweet.Id, ReactionId = reaction.Id
            };

            await _repository.Toggle(userTweetReaction);

            models = _dbContext.UserTweetReaction.ToList();
            Assert.AreEqual(1, models.Count);

            userTweetReaction.Id = 0;
            await _repository.Toggle(userTweetReaction);

            models = _dbContext.UserTweetReaction.ToList();
            Assert.AreEqual(0, models.Count);
        }
Exemplo n.º 5
0
        public ActionResult Reactions(ReactionModel model)
        {
            var fb = new Facebook.FacebookClient();

            fb.AccessToken = model.Token;
            fb.Post()
            return(View());
        }
Exemplo n.º 6
0
        public PotionModel GetPotionByReaction(ReactionModel reaction)
        {
            var potion = _reactionRepository.Select()
                         .Where(x => x.Process == reaction.Process)
                         .Where(x => x.Reagent == reaction.Reagent)
                         .Select(x => x.Potion).First();

            return(Mapper.Map <PotionModel>(potion));
        }
 internal DiscordReaction(ReactionModel model)
 {
     Count = model.Count;
     Me    = model.Me;
     if (model.Emoji != null)
     {
         Emoji = new DiscordEmoji(model.Emoji);
     }
 }
Exemplo n.º 8
0
        public IActionResult DeleteReaction(ReactionModel reaction)
        {
            if (!int.TryParse(HttpContext.Session.GetString("UserId"), out int activeUserId))
            {
                return(Json(new JSONResponse(false, "Unexpected Error")));
            }

            this.reactions.Remove(reaction.TextId, activeUserId);

            return(Json(new JSONResponse(true)));
        }
Exemplo n.º 9
0
        public void InsertReaction()
        {
            ReactionRepository reactionRepository = new ReactionRepository(new InMemoryDbContextFactory().CreateDbContext());

            UserModel userModel = new UserModel
            {
                Id              = Guid.NewGuid(),
                Name            = "Peter",
                Surname         = "Petigriu",
                Email           = "*****@*****.**",
                Password        = "******",
                TelephoneNumber = "4206666666666"
            };

            GroupModel groupModel = new GroupModel
            {
                Id          = Guid.NewGuid(),
                Name        = "Yzomandias",
                Description = "Skupina pro organizaci vystoupení spolu s umělcem PTK",
            };

            GroupMemberModel groupMemberModel = new GroupMemberModel
            {
                Id         = Guid.NewGuid(),
                User       = userModel,
                Group      = groupModel,
                Permission = PermissionEnum.Moderator
            };

            ContributionModel contributionModel = new ContributionModel
            {
                Id      = Guid.NewGuid(),
                User    = userModel,
                Group   = groupModel,
                Message = "Přijede muzika sraz v 9 večer Severka",
                Title   = "Přijede muzika",
                Time    = DateTime.MaxValue
            };

            ReactionModel reactionModel = new ReactionModel
            {
                Id           = Guid.NewGuid(),
                User         = userModel,
                Contribution = contributionModel,
                ReactionType = ReactionTypeEnum.Booze
            };

            reactionRepository.Insert(reactionModel);
            var reactionRepositoryResponse = reactionRepository.getReactionByUserId(userModel.Id);

            Assert.NotNull(reactionRepositoryResponse);
        }
Exemplo n.º 10
0
        private string FormatAddOrUpdateQuery(string sql, ReactionModel reaction)
        {
            var rowsAndParams = GetColumnsAndParams(reaction);
            var columns       = rowsAndParams[0];
            var parameters    = rowsAndParams[1];

            string         columnsString    = string.Join(", ", columns);
            string         parametersString = string.Join(", ", parameters);
            IList <string> pairs            = GetPairs(columns, parameters);
            string         updateString     = string.Join(", ", pairs);

            return(string.Format(sql, columnsString, parametersString, updateString));
        }
Exemplo n.º 11
0
        public async Task <Reaction> Create(Reaction reaction)
        {
            ReactionModel model = new ReactionModel {
                Name = reaction.Name
            };

            _dbContext.Add <ReactionModel>(model);
            await _dbContext.SaveChangesAsync();

            reaction.Id = model.Id;

            return(reaction);
        }
Exemplo n.º 12
0
        public async Task <IActionResult> AddReaction([FromBody] ReactionModel ReactionData)
        {
            var thisUser = await userManager.GetUserAsync(HttpContext.User);

            Post reactedPost;

            if (ModelState.IsValid)
            {
                Reaction postReaction = dataRepository.GetReactionByPostAndUser(ReactionData.PostID, thisUser);

                // Does the reaction already exist?
                if (postReaction is null)
                {
                    reactedPost  = dataRepository.GetPostById(ReactionData.PostID);
                    postReaction = new Reaction
                    {
                        Post   = reactedPost,
                        User   = thisUser,
                        IsLike = ReactionData.IsLike
                    };

                    dataRepository.AddEntity(postReaction);

                    if (dataRepository.SaveAll())
                    {
                        logger.LogInformation("NEW Reaction Saved to Database");
                    }
                    ;
                }
                else
                {
                    if (postReaction.IsLike != ReactionData.IsLike)
                    {
                        postReaction.IsLike = ReactionData.IsLike;
                        if (dataRepository.SaveAll())
                        {
                            logger.LogInformation("Reaction was changed and Saved to Database");
                        }
                        ;
                    }
                }
            }
            reactedPost = dataRepository.GetPostById(ReactionData.PostID);

            // Return the new amount of likes and dislikes
            return(Json(new
            {
                likes = reactedPost.Reactions.Where(r => r.IsLike).ToList().Count,
                dislikes = reactedPost.Reactions.Where(r => !r.IsLike).ToList().Count
            }));
        }
Exemplo n.º 13
0
        public void store_and_delete_a_reaction()
        {
            Connection one = new Connection();
            Connection two = new Connection();

            ReactionRepo repo  = new ReactionRepo(new Connection());
            MessageRepo  mRepo = new MessageRepo(new Connection(), new ReactionRepo(new Connection()));

            //Create message that reaction will belong to

            MessageModel message = new MessageModel();

            message.message  = "testmessage";
            message.subject  = "subject";
            message.forum    = "1";
            message.software = "1";

            int id = mRepo.store(message, 1);

            //Create reaction

            ReactionModel reaction = new ReactionModel();

            reaction.message_id = id;
            reaction.lastName   = "lastname";
            reaction.reaction   = "reaction";

            int idTwo = repo.store(reaction, 1);

            reaction.id = idTwo;

            one.Connect();
            SqlCommand    sqlCommand = new SqlCommand("select * from reaction where reaction = 'reaction'", one.getConnection());
            SqlDataReader reader     = sqlCommand.ExecuteReader();

            Assert.AreEqual(true, reader.HasRows);
            one.disConnect();

            //Delete reaction

            repo.destroy(id);

            two.Connect();

            SqlCommand    sqlCommandTwo = new SqlCommand("select * from corporation where name = 'name' and email ='email' and zip = '3434-kj' and address = 'address'", two.getConnection());
            SqlDataReader readerTwo     = sqlCommandTwo.ExecuteReader();

            Assert.AreEqual(false, readerTwo.HasRows);
            one.disConnect();
        }
Exemplo n.º 14
0
        public IActionResult destroy([FromBody] ReactionModel reaction)
        {
            try
            {
                reactionRepo.destroy(reaction.id);
                return(StatusCode(200));
            }

            catch (Exception ex)
            {
                errors.log(ex);
                return(Json(null));
            }
        }
Exemplo n.º 15
0
        private bool hasNotVoted(ReactionModel reaction)
        {
            List <Reaction> reactions = getReactions(reaction.Item.TS);

            //Checks if the voter has voted for the same post before
            int userCount = reactions.Where(r => r.users.Contains(reaction.User)).Count();

            if (userCount > 1)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 16
0
        public IActionResult store([FromBody] ReactionModel reaction)
        {
            try
            {
                int authId = Convert.ToInt32(User.Claims.Single(c => c.Type == "id").Value);
                int id     = reactionRepo.store(reaction, authId);
                return(Json(reactionRepo.find(id)));
            }

            catch (Exception ex)
            {
                errors.log(ex);
                return(Json(null));
            }
        }
        public void HandleVotes(Bot bot)
        {
            //Message event handler
            bot.MessageReceived += (message) =>
            {
                ReactionModel reaction = JsonConvert.DeserializeObject <ReactionModel>(message);
                if (reaction.Type.Equals("reaction_added"))
                {
                    webApi.SaveVote(reaction);
                }

                if (reaction.Type.Equals("reaction_removed"))
                {
                    webApi.RemoveVote(reaction);
                }
            };
        }
Exemplo n.º 18
0
        private EmbedFieldBuilder GetField(ReactionModel reaction)
        {
            string trigger  = Format(reaction.Trigger);
            string response = Format(reaction.Response);

            string value =
                $"**Trigger**:{trigger} **Response**:{response} **Anywhere**:{reaction.Anywhere} **Weight**:{reaction.Weight}\n\u200B";

            EmbedFieldBuilder builder = new()
            {
                IsInline = false,
                Name     = $"**{reaction.Id}**",
                Value    = value
            };

            return(builder);
        }
Exemplo n.º 19
0
        public void update_a_message()
        {
            Connection one = new Connection();
            Connection two = new Connection();

            ReactionRepo repo  = new ReactionRepo(new Connection());
            MessageRepo  mRepo = new MessageRepo(new Connection(), new ReactionRepo(new Connection()));

            //Create message that reaction will belong to

            MessageModel message = new MessageModel();

            message.message  = "testmessage";
            message.subject  = "subject";
            message.forum    = "1";
            message.software = "1";

            int id = mRepo.store(message, 1);

            //Create reaction

            ReactionModel reaction = new ReactionModel();

            reaction.message_id = id;
            reaction.lastName   = "lastname";
            reaction.reaction   = "reaction";

            int idTwo = repo.store(reaction, 1);

            reaction.id = idTwo;
            //Give forum a new name

            reaction.reaction = "new name!";

            repo.update(reaction);

            one.Connect();
            SqlCommand    sqlCommand = new SqlCommand("select * from reaction where reaction = 'new name!'", one.getConnection());
            SqlDataReader reader     = sqlCommand.ExecuteReader();

            Assert.AreEqual(true, reader.HasRows);
            one.disConnect();

            repo.destroy(id);
        }
Exemplo n.º 20
0
        private List <string>[] GetColumnsAndParams(ReactionModel reaction)
        {
            List <string> columns    = new();
            List <string> parameters = new();

            AddIfNotNull(columns, reaction.Trigger, "text_trigger");
            AddIfNotNull(parameters, reaction.Trigger, "@Trigger");
            AddIfNotNull(columns, reaction.Response, "text_response");
            AddIfNotNull(parameters, reaction.Response, "@Response");
            AddIfNotNull(columns, reaction.Anywhere, "anywhere");
            AddIfNotNull(parameters, reaction.Anywhere, "@Anywhere");
            AddIfNotNull(columns, reaction.Weight, "weight");
            AddIfNotNull(parameters, reaction.Weight, "@Weight");

            var result = new[] { columns, parameters };

            return(result);
        }
        public async Task <UserTweetReaction> Toggle(UserTweetReaction userTweetReaction)
        {
            AppUser user = await _dbContext.Users.FirstOrDefaultAsync(u => u.Id == userTweetReaction.UserId);

            TweetModel tweetModel = await _dbContext.Tweet.FirstOrDefaultAsync(t => t.Id == userTweetReaction.TweetId);

            ReactionModel reactionModel = await _dbContext.Reaction.FirstOrDefaultAsync(r => r.Id == userTweetReaction.ReactionId);

            if (user == null || tweetModel == null || reactionModel == null)
            {
                throw new ArgumentNullException("Invalid input");
            }

            UserTweetReactionModel model = await _dbContext.UserTweetReaction
                                           .FirstOrDefaultAsync(u => u.UserId == userTweetReaction.UserId && u.TweetId == userTweetReaction.TweetId && u.ReactionId == userTweetReaction.ReactionId);

            if (model != null)
            {
                _dbContext.Remove <UserTweetReactionModel>(model);
                await _dbContext.SaveChangesAsync();

                return(null);
            }

            model = new UserTweetReactionModel
            {
                UserId     = userTweetReaction.UserId,
                TweetId    = userTweetReaction.TweetId,
                ReactionId = userTweetReaction.ReactionId
            };

            _dbContext.Add <UserTweetReactionModel>(model);
            await _dbContext.SaveChangesAsync();

            userTweetReaction.Id    = model.Id;
            userTweetReaction.User  = user;
            userTweetReaction.Tweet = new Tweet {
                Id = tweetModel.Id, Text = tweetModel.Text
            };
            userTweetReaction.Reaction    = new Reaction(name: reactionModel.Name);
            userTweetReaction.Reaction.Id = reactionModel.Id;

            return(userTweetReaction);
        }
Exemplo n.º 22
0
        public IActionResult AddReaction(ReactionModel reaction)
        {
            if (!int.TryParse(HttpContext.Session.GetString("UserId"), out int activeUserId))
            {
                return(Json(new JSONResponse(false, "Unexpected Error")));
            }

            var newReaction = (new Data.Models.Reaction()
            {
                Creator = this.users.GetById(activeUserId),
                CreatorId = activeUserId,
                CreationDate = DateTime.Now,
                UserText = this.userTexts.GetById(reaction.TextId),
                UserTextId = reaction.TextId,
                ReactionType = ReactionType.like
            });

            this.reactions.Add(newReaction);
            return(Json(new JSONResponse(true)));
        }
Exemplo n.º 23
0
        private (AppUser, TweetModel, ReactionModel) populate()
        {
            AppUser user = new AppUser {
                Nickname = "marcow"
            };
            ReactionModel reaction = new ReactionModel {
                Name = "Star"
            };

            _dbContext.Add <AppUser>(user);
            _dbContext.Add <ReactionModel>(reaction);
            _dbContext.SaveChanges();
            TweetModel tweet = new TweetModel {
                UserId = user.Id, Text = "Super First Tweet"
            };

            _dbContext.Add <TweetModel>(tweet);
            _dbContext.SaveChanges();

            return(user, tweet, reaction);
        }
Exemplo n.º 24
0
        public async Task IsReactingToManyInRepo()
        {
            this.populateMany();

            AppUser       marcow = _dbContext.Users.FirstOrDefault(u => u.Nickname == "marcow");
            TweetModel    tweet1 = _dbContext.Tweet.FirstOrDefault(t => t.UserId == marcow.Id);
            ReactionModel star   = _dbContext.Reaction.FirstOrDefault(r => r.Name == "Star");
            ReactionModel heart  = _dbContext.Reaction.FirstOrDefault(r => r.Name == "Heart");
            ReactionModel cross  = _dbContext.Reaction.FirstOrDefault(r => r.Name == "Cross");

            var r1 = new UserTweetReaction {
                UserId = marcow.Id, TweetId = tweet1.Id, ReactionId = star.Id
            };
            var r2 = new UserTweetReaction {
                UserId = marcow.Id, TweetId = tweet1.Id, ReactionId = heart.Id
            };
            var r3 = new UserTweetReaction {
                UserId = marcow.Id, TweetId = tweet1.Id, ReactionId = cross.Id
            };

            await _repository.Toggle(r1);

            await _repository.Toggle(r2);

            await _repository.Toggle(r3);

            IEnumerable <UserTweetReactionModel> setupReactions = _dbContext.UserTweetReaction.ToList();

            Assert.AreEqual(3, setupReactions.Count());

            var requestReactions = new UserTweetReaction[] { r1, r1, r3 };

            IEnumerable <UserTweetReaction> resultReacions = await _repository.ReactedToMany(requestReactions);

            foreach (UserTweetReaction u in resultReacions)
            {
                Assert.True(u.Reacted);
            }
        }
Exemplo n.º 25
0
        private void populateMany()
        {
            AppUser user = new AppUser {
                Nickname = "marcow"
            };
            AppUser joe = new AppUser {
                Nickname = "joe"
            };

            _dbContext.Add <AppUser>(user);
            _dbContext.Add <AppUser>(joe);

            ReactionModel star = new ReactionModel {
                Name = "Star"
            };
            ReactionModel heart = new ReactionModel {
                Name = "Heart"
            };
            ReactionModel cross = new ReactionModel {
                Name = "Cross"
            };

            _dbContext.Add <ReactionModel>(star);
            _dbContext.Add <ReactionModel>(heart);
            _dbContext.Add <ReactionModel>(cross);

            _dbContext.SaveChanges();

            TweetModel tweet1 = new TweetModel {
                UserId = user.Id, Text = "Super First Tweet"
            };
            TweetModel tweet2 = new TweetModel {
                UserId = joe.Id, Text = "Joe s tweet"
            };

            _dbContext.Add <TweetModel>(tweet1);
            _dbContext.Add <TweetModel>(tweet2);
            _dbContext.SaveChanges();
        }
Exemplo n.º 26
0
        public SavePostResponseModel SaveVote(ReactionModel reaction)
        {
            if (hasNotVoted(reaction) &&
                (reaction.Reaction.Contains("+1") || reaction.Reaction.Contains("-1")))
            {
                var client = new RestClient(ServerAddress);

                var request = new RestRequest("Reactions/CreateReaction", Method.POST);

                request.AddParameter("SlackUserId", reaction.User);
                request.AddParameter("Reaction", reaction.Reaction);
                request.AddParameter("MessageTimeStamp", reaction.Item.TS.ToString());

                IRestResponse response = client.Execute(request);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    return new SavePostResponseModel {
                               StatusCode = response.StatusCode
                    }
                }
                ;

                //If there are errors
                return(new SavePostResponseModel
                {
                    StatusCode = response.StatusCode,
                    ErrorMessage = response.Content
                });
            }

            return(new SavePostResponseModel
            {
                StatusCode = System.Net.HttpStatusCode.BadRequest,
                ErrorMessage = "Your vote was not counted as you have voted before",
            });
        }
Exemplo n.º 27
0
        public PartialViewResult OnGetResult(ReactionModel reaction)
        {
            var potion = _alchemyService.GetPotionByReaction(reaction);

            return(Partial(SitePages.MajorAlchemy_Result, potion));
        }
Exemplo n.º 28
0
        public IList <ReactionModel> GetAllReactions(ReactionModel reaction)
        {
            string sql = GetAllReactionsQuery(reaction);

            return(_data.LoadData <ReactionModel, object>(sql, reaction));
        }
Exemplo n.º 29
0
 public ReactionModel Update(int id, ReactionModel ReactionModel)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 30
0
 public ReactionModel Create(ReactionModel ReactionModel)
 {
     _dbReference.ReactionModel.Add(ReactionModel);
     _dbReference.SaveChanges();
     return(ReactionModel);
 }