Esempio n. 1
0
        public async Task <IActionResult> PostUpvote([FromBody] Upvote upvote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var GitHubEmail = User.FindFirst(c => c.Type == ClaimTypes.Email)?.Value;

            var user = _context.Users
                       .Where(b => b.UserEmail == GitHubEmail)
                       .FirstOrDefault();

            upvote.UserId = user.UserId;

            var upvoteCheck = _context.Upvotes
                              .Where(b => b.PostId == upvote.PostId && b.UserId == upvote.UserId);

            if (upvoteCheck.Any())
            {
                return(Conflict());
            }
            upvote.Id = Guid.NewGuid().ToString();
            _context.Upvotes.Add(upvote);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetUpvote", new { id = upvote.Id }, upvote));
        }
Esempio n. 2
0
        // The result of the Like-button
        public ActionResult UpvoteSubtitle(int subtitleFileID)
        {
            // Checks whether an upvote with the same username and SubtitleFile ID exists.
            // Return null otherwise.
            Upvote u = SubtitleRepository.Instance.GetUpvoteByID(subtitleFileID);

            // Retrieves the subtitle with the given ID.
            SubtitleFile subtitle = SubtitleRepository.Instance.GetSubtitleByID(subtitleFileID);

            // Removes the upvote if it exists
            if (u != null)
            {
                SubtitleRepository.Instance.RemoveUpvote(u);
                subtitle.upvote--;
                SubtitleRepository.Instance.Save();
            }
            // Creates a new one otherwise.
            else
            {
                SubtitleRepository.Instance.AddUpvote(new Upvote
                {
                    SubtitleFileID    = subtitleFileID,
                    applicationUserID = System.Security.Principal.WindowsIdentity.GetCurrent().Name
                });
                subtitle.upvote++;
                SubtitleRepository.Instance.Save();
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public async Task <IActionResult> PutUpvote([FromRoute] string id, [FromBody] Upvote upvote)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != upvote.Id)
            {
                return(BadRequest());
            }

            _context.Entry(upvote).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UpvoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 4
0
        public async Task <ActionResult <Upvote> > PostUpvote(Upvote upvote)
        {
            _context.Upvotes.Add(upvote);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetUpvote), new { id = upvote.ID }, upvote));
        }
Esempio n. 5
0
        public IActionResult Upvote(UpvoteDto dto)
        {
            var userId = GetLoggedInUser().Id;

            if (_context.Upvotes.Any(a => a.UpvoterId == userId && a.PostId == dto.PostId))
            {
                return(BadRequest("The upvote already exists."));
            }

            var post = _context.Posts
                       .Include(p => p.Artist)
                       .Single(p => p.ID == dto.PostId);

            post.LikeCount++;
            //post.IsLiked = true;
            _context.Posts.Update(post);

            var upvote = new Upvote
            {
                UpvoterId = userId,
                PostId    = dto.PostId
            };

            _context.Upvotes.Add(upvote);

            var notification = new Notification
            {
                Type     = NotificationType.PostLiked,
                DateTime = DateTime.Now,
                Post     = post,
                ActorId  = userId
            };

            _context.Notifications.Add(notification);

            var postCreator = _context.Posts
                              .Where(p => p.ID == post.ID)
                              .Select(p => p.Artist)
                              .SingleOrDefault();

            var userNotification = new UserNotification
            {
                NotificationId = notification.Id,
                UserId         = postCreator.Id
            };

            postCreator.UserNotifications.Add(userNotification);
            _context.Update(postCreator);
            _context.SaveChanges();

            var postDto = new PostDto
            {
                Id        = post.ID,
                LikeCount = post.LikeCount
            };

            return(Ok(postDto));
        }
Esempio n. 6
0
        public async Task <IActionResult> UpvoteGame(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (await _boardologyRepo.GetGame(gameId) == null)
            {
                return(NotFound());
            }

            var upvote = await _votesRepo.GetUpvote(userId, gameId);

            var downvote = await _votesRepo.GetDownvote(userId, gameId);

            if (upvote != null)
            {
                await _votesRepo.DecreaseUpvotes(gameId);

                _boardologyRepo.Delete(upvote);
                if (await _boardologyRepo.SaveAll())
                {
                    return(Ok());
                }
                return(BadRequest("Failed to remove upvote"));
            }



            upvote = new Upvote
            {
                UpVoterId = userId,
                GameId    = gameId
            };

            _boardologyRepo.Add(upvote);

            await _votesRepo.IncreaseUpvotes(gameId);

            if (downvote != null)
            {
                await _votesRepo.DecreaseDownvotes(gameId);

                _boardologyRepo.Delete(downvote);
            }


            if (await _boardologyRepo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to upvote game"));
        }
Esempio n. 7
0
        public override async Task <UpvoteReply> AddUpvote(AddUpvoteRequest request, ServerCallContext context)
        {
            var upvote = new Upvote
            {
                UserId   = int.Parse(context.GetHttpContext().User.Identity.Name),
                IdiomId  = request.IdiomId,
                IsUpvote = request.IsUpvote
            };
            await _actions.AddOrChangeUpvote(upvote);

            return(upvote.ToReply());
        }
Esempio n. 8
0
        public async Task <IActionResult> Upvote(int id)
        {
            Upvote upvote = new Upvote()
            {
                LikedOn = DateTime.UtcNow,
                Report  = _reportRepository.GetReportById(id),
                User    = await _userManager.GetUserAsync(User)
            };

            _upvoteRepository.AddUpvote(upvote);

            return(RedirectToAction("Details", new { id }));
        }
Esempio n. 9
0
        public IActionResult Like(int messageId)
        {
            string user = Request.Cookies["user"];
            var    acc  = db.Accounts.Include(a => a.Messages)
                          .Include(a => a.Upvotes)
                          .SingleOrDefault(a => a.Username == user);

            var upvote = new Upvote()
            {
                MessageId = messageId, AccountId = acc.ID
            };

            acc.Upvotes.Add(upvote);
            db.SaveChanges();
            return(RedirectToAction("index"));
        }
Esempio n. 10
0
        public async Task <bool> AddOrChangeUpvote(Upvote upvote)
        {
            var check = await _db.Upvotes.FirstOrDefaultAsync(x => x.IdiomId == upvote.IdiomId && x.UserId == upvote.UserId);

            if (check == null)
            {
                _db.Upvotes.Add(upvote);
                await _db.SaveChangesAsync();
            }
            else
            {
                check.IsUpvote = upvote.IsUpvote;
                _db.Upvotes.Update(check);
                await _db.SaveChangesAsync();
            }
            return(true);
        }
Esempio n. 11
0
        public void Vote(string username, string upvotableEntityId, IUpvotablesService entityService, bool isDownvote)
        {
            IUpvotableEntity upvotable = entityService.ResolveUpvotableEntity(upvotableEntityId);

            var user = _usersService.GetByUsername(username);

            if (user == null)
            {
                return;
            }

            int voteWeight = isDownvote ? -1 : 1;

            Upvote entity = new Upvote();

            entity.UserId = user.UserId;
            entity.Weight = voteWeight;

            var votes = _dbContext.Upvotes.Where(uv => uv.VotingBoxId == upvotable.VotingBoxId && uv.UserId == user.UserId).ToList();

            if (votes == null)
            {
                entity.VotingBoxId = upvotable.VotingBoxId;
                _dbContext.Upvotes.Add(entity);
                _dbContext.SaveChanges();
                return;
            }

            if (votes != null && votes.Count == 1 && votes.First().Weight == voteWeight)
            {
                return;
            }
            else
            {
                _dbContext.RemoveRange(votes);
                entity.VotingBoxId = upvotable.VotingBoxId;
                _dbContext.Upvotes.Add(entity);
                _dbContext.SaveChanges();
            }
        }
Esempio n. 12
0
        public void UpvoteComment(int?id)
        {
            Comment comment = db.Comment.Find(id);
            Upvote  Upvote  = comment.Upvotes.Where(item => item.UserID.Equals(this.User.Identity.GetUserId())).FirstOrDefault();

            if (Upvote == null)
            {
                comment.Upvote_count    = comment.Upvote_count + 1;
                db.Entry(comment).State = EntityState.Modified;
                db.Upvote.Add(new Upvote {
                    CommentID = comment.CommentID, UserID = this.User.Identity.GetUserId(), Created = DateTime.Now
                });
                db.SaveChanges();
            }
            else
            {
                comment.Upvote_count    = comment.Upvote_count - 1;
                db.Entry(comment).State = EntityState.Modified;
                db.Upvote.Remove(Upvote);
                db.SaveChanges();
            }
        }
Esempio n. 13
0
        public async Task UpvoteAsync(Guid postId, Guid userId)
        {
            var post = await _postsRepository.GetByIdAsync(postId, p => p
                                                           .Include(e => e.Upvotes)
                                                           .Include(e => e.Downvotes));

            var upvote = post.Upvotes.SingleOrDefault(u => u.UserId == userId);

            if (upvote == null)
            {
                upvote = new Upvote(userId, postId);
                post.Upvotes.Add(upvote);
            }
            else
            {
                post.Upvotes.Remove(upvote);
            }

            // TODO test to see if it is necessary to use an upvotes repository
            post.UpdateRating();
            await _postsRepository.UpdateAsync(post);
        }
Esempio n. 14
0
        public void UpvoteComment(int CommentId, string UserId)
        {
            Comment comment = Database.Comments.Get(CommentId);
            Upvote  Upvote  = comment.Upvotes.Where(item => item.UserID.Equals(UserId)).FirstOrDefault();

            if (Upvote == null)
            {
                comment.Upvote_count = comment.Upvote_count + 1;
                comment.Upvotes.Add(new Upvote {
                    CommentID = comment.ID, UserID = UserId, Created = DateTime.Now
                });

                Database.Comments.Update(comment);
                Database.Save();
            }
            else
            {
                comment.Upvote_count = comment.Upvote_count - 1;
                Database.Upvotes.Delete(Upvote.UpvoteID);

                Database.Save();
            }
        }
Esempio n. 15
0
        public ActionResult Details(int id, string submit)
        {
            var answer = db.Answers.Find(id);

            switch (submit)


            {
            case "Upvote":
                var upvote = new Upvote
                {
                    VoterId  = User.Identity.GetUserId(),
                    AnswerId = id
                };

                db.Upvotes.Add(upvote);
                db.SaveChanges();
                int votecount = db.Upvotes.Where(u => u.AnswerId == id).ToList().Count;
                answer.Score           = votecount;
                db.Entry(answer).State = EntityState.Modified;
                break;

            case "Unvote":
                var    me      = User.Identity.GetUserId();
                Upvote upvote1 = db.Upvotes.Where(u => (u.VoterId == me && u.AnswerId == id)).FirstOrDefault();
                db.Upvotes.Remove(upvote1);
                db.SaveChanges();
                int votecount1 = db.Upvotes.Where(u => u.AnswerId == id).ToList().Count;
                answer.Score           = votecount1;
                db.Entry(answer).State = EntityState.Modified;
                break;
            }

            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 16
0
        public async Task <IActionResult> UpvoteGame(int userId, int gameId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }
            var upvote = await _repo.GetUpvote(userId, gameId);

            if (upvote != null)
            {
                return(BadRequest("You already upvoted this game"));
            }

            if (await _repo.GetGame(gameId) == null)
            {
                return(NotFound());
            }

            upvote = new Upvote
            {
                UpVoterId = userId,
                GameId    = gameId
            };

            _repo.Add(upvote);

            await _repo.IncreaseUpvotes(gameId);


            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to upvote game"));
        }
Esempio n. 17
0
        public static void Init()
        {
            try
            {
                var upvoteItem = Upvote.Initialize(Global.Name, 7);

                AppDomain.CurrentDomain.UnhandledException +=
                    delegate(object sender, UnhandledExceptionEventArgs eventArgs)
                {
                    try
                    {
                        var ex = sender as Exception;
                        if (ex != null)
                        {
                            Global.Logger.AddItem(new LogItem(ex));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                };

                SetupLanguage();

                GameObjects.Initialize();

                CustomEvents.Game.OnGameLoad += delegate
                {
                    try
                    {
                        _champion = LoadChampion();

                        if (_champion != null)
                        {
                            try
                            {
                                Update.Check(
                                    Global.Name, Assembly.GetExecutingAssembly().GetName().Version, Global.UpdatePath,
                                    10000);
                            }
                            catch (Exception ex)
                            {
                                Global.Logger.AddItem(new LogItem(ex));
                            }
                            Core.Init(_champion, 50);
                            Core.Boot();

                            if (_champion.SFXMenu != null && upvoteItem != null)
                            {
                                _champion.SFXMenu.SubMenu(_champion.SFXMenu.Name + ".settings").AddItem(upvoteItem);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Global.Logger.AddItem(new LogItem(ex));
                    }
                };
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
Esempio n. 18
0
        //获取指定id的点赞
        public Upvote getById(int id)
        {
            Upvote upvote = db.upvotes.Where(u => u.ID == id).FirstOrDefault();

            return(upvote);
        }
Esempio n. 19
0
        public static void Init()
        {
            try
            {
                #region Upvote

                var upvoteItem = Upvote.Initialize(Global.Name, 7);

                #endregion Upvote

                AppDomain.CurrentDomain.UnhandledException +=
                    delegate(object sender, UnhandledExceptionEventArgs eventArgs)
                {
                    try
                    {
                        var ex = sender as Exception;
                        if (ex != null)
                        {
                            Global.Logger.AddItem(new LogItem(ex));
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                };

                SetupLanguage();

                #region GameObjects

                GameObjects.Initialize();

                #endregion GameObjects

                Global.SFX = new SFXUtility();

                #region Upvote

                Global.SFX.Menu.SubMenu(Global.SFX.Name + "Settings").AddItem(upvoteItem);

                #endregion Upvote

                #region Parents

                var activators = new Activators();
                var detectors  = new Detectors();
                var drawings   = new Drawings();
                var events     = new Events();
                var others     = new Others();
                var timers     = new Timers();
                var trackers   = new Trackers();

                #endregion Parents

                CustomEvents.Game.OnGameLoad += delegate
                {
                    Global.Features.AddRange(
                        new List <IChild>
                    {
                        #region Features
                        new KillSteal(activators),
                        new Potion(activators),
                        new Revealer(activators),
                        new Smite(activators),
                        new Gank(detectors),
                        new Replay(detectors),
                        new Teleport(detectors),
                        new Clock(drawings),
                        new Clone(drawings),
                        new DamageIndicator(drawings),
                        new Health(drawings),
                        new LasthitMarker(drawings),
                        new PerfectWard(drawings),
                        new Range(drawings),
                        new SafeJungleSpot(drawings),
                        new WallJumpSpot(drawings),
                        new Waypoint(drawings),
                        new AutoLeveler(events),
                        new Game(events),
                        new Trinket(events),
                        new AntiFountain(others),
                        new AutoLantern(others),
                        new Flash(others),
                        new Humanize(others),
                        new MoveTo(others),
                        new Ping(others),
                        new TurnAround(others),
                        new Ability(timers),
                        new Altar(timers),
                        new Cooldown(timers),
                        new Relic(timers),
                        new Inhibitor(timers),
                        new Jungle(timers),
                        new GoldEfficiency(trackers),
                        new Destination(trackers),
                        new LastPosition(trackers),
                        new Sidebar(trackers),
                        new Ward(trackers)
                        #endregion Features
                    });
                    foreach (var feature in Global.Features)
                    {
                        try
                        {
                            feature.HandleEvents();
                        }
                        catch (Exception ex)
                        {
                            Global.Logger.AddItem(new LogItem(ex));
                        }
                    }
                    try
                    {
                        Update.Check(
                            Global.Name, Assembly.GetExecutingAssembly().GetName().Version, Global.UpdatePath, 10000);
                    }
                    catch (Exception ex)
                    {
                        Global.Logger.AddItem(new LogItem(ex));
                    }
                };
            }
            catch (Exception ex)
            {
                Global.Logger.AddItem(new LogItem(ex));
            }
        }
Esempio n. 20
0
 public static UpvoteReply ToReply(this Upvote upvote) => new UpvoteReply
 {
     UpvoteId = upvote.UpvoteId, IdiomId = upvote.IdiomId, IsUpvote = upvote.IsUpvote, UserId = upvote.UserId
 };
Esempio n. 21
0
 public async Task <BaseObject> Upvote(ActivityDeliveryContext ctx, Upvote upvote) => await ReactAndGetSummary(ctx, upvote, ReactionType.Upvote);
Esempio n. 22
0
 //添加点赞
 public void add(Upvote upvote)
 {
     db.upvotes.Add(upvote);
     db.SaveChanges();
 }