Пример #1
0
        public async Task <IActionResult> Tree(int id)
        {
            Argument thisArgument = _db.Arguments.FirstOrDefault(a => a.ArgumentId == id);

            thisArgument.AddChildrenRecursive();
            thisArgument.AddParent();
            ViewBag.UserType = 0;
            ViewBag.Citation = _db.Citations.FirstOrDefault(c => c.ArgumentId == id);
            ApplicationUser user = await GetCurrentUser();

            if (user != null)
            {
                ViewBag.UserVotes = _db.Votes.Where(v => v.UserId == user.Id).ToList();
            }
            else
            {
                ViewBag.UserVotes = new List <Vote>();
            }
            if (User.IsInRole("user"))
            {
                ViewBag.UserType = 1;
            }
            else if (User.IsInRole("admin"))
            {
                ViewBag.UserType = 2;
            }
            return(View(thisArgument));
        }
Пример #2
0
        public IActionResult Details(int id)
        {
            Argument argument = _db.Arguments
                                .Include(a => a.ProposedEdits)
                                .ThenInclude(pe => pe.User)
                                .Include(a => a.User)
                                .FirstOrDefault(a => a.ArgumentId == id);

            argument.AddChildrenRecursive();
            argument.AddLink();
            ViewBag.Citation = _db.Citations.FirstOrDefault(c => c.ArgumentId == id);
            return(View(argument));
        }
Пример #3
0
        public async Task <IActionResult> Vote(int id)
        {
            ApplicationUser current = await GetCurrentUser();

            Argument argument = _db.Arguments.FirstOrDefault(a => a.ArgumentId == id);

            if (argument.LinkId != 0)
            {
                return(Content("{}", "text/plain"));
            }
            Vote existingVote = _db.Votes.FirstOrDefault(v => v.UserId == current.Id && v.ArgumentId == argument.ArgumentId);

            if (existingVote == null)
            {
                argument.Strength = argument.Strength + 1;
                Vote vote = new Vote();
                vote.ArgumentId = argument.ArgumentId;
                vote.UserId     = current.Id;
                _db.Votes.Add(vote);
            }
            else
            {
                argument.Strength = argument.Strength - 1;
                _db.Votes.Remove(existingVote);
            }
            _db.Entry(argument).State = EntityState.Modified;
            _db.SaveChanges();
            string response = "{";

            while (argument.ParentId != 0)
            {
                argument.AddChildrenRecursive();
                response += "\"" + argument.ArgumentId.ToString() + "\": " + argument.GetTotalStrength().ToString() + ",";
                argument  = argument.AddParent();
            }
            argument.AddChildrenRecursive();
            response += "\"" + argument.ArgumentId.ToString() + "\": " + argument.GetTotalStrength().ToString() + "}";
            return(Content(response, "text/plain"));
        }
Пример #4
0
        public async Task <IActionResult> ProposeEdit(int id)
        {
            Argument argument = _db.Arguments.FirstOrDefault(a => a.ArgumentId == id);

            argument.AddChildrenRecursive();
            Argument        root = argument.GetRoot();
            ApplicationUser user = await GetCurrentUser();

            if (user != null)
            {
                ViewBag.UserVotes = _db.Votes.Where(v => v.UserId == user.Id).ToList();
            }
            else
            {
                ViewBag.UserVotes = new List <Vote>();
            }
            root.AddChildrenRecursive();
            ViewBag.Root = root;
            return(View(argument));
        }