示例#1
0
 public ActionResult UnlikeO(int? id, int? user)
 {
     RedisUserRepository redisUser = new RedisUserRepository();
     RedisOreRepository redisOre = new RedisOreRepository();
     if (id == null || user == null)
     {
         return RedirectToAction("Index", "Ore");
     }
     if (JsonConvert.DeserializeObject<User>(Context.Session.GetString("user")) != null)
     {
         User inQuestion = JsonConvert.DeserializeObject<User>(Context.Session.GetString("user"));
         if (inQuestion.PasswordHash != redisUser.ReadUser((int)user).PasswordHash)
         {
             return RedirectToAction("Index", "Ore");
         }
     }
     else
     {
         return RedirectToAction("Login", "Community");
     }
     User author = redisUser.ReadUser((int)user);
     Ore target = redisOre.ReadOre((int)id);
     if (!author.CommentsLiked.Contains((int)id))
     {
         target.Likes -= 1;
         redisOre.CreateOre(target);
         author.OresLiked.Add((int)id);
         redisUser.UpdateUser(author);
     }
     Context.Session.SetString("user", JsonConvert.SerializeObject(author));
     return RedirectToAction("Info", "Ore", new { oreName = redisOre.ReadOre((int)id) });
 }
示例#2
0
 public ActionResult Comments(int? oreId)
 {
     if (oreId == 0 || oreId == null) { return RedirectToAction("Index", "Ore"); }
     RedisOreRepository redisOre = new RedisOreRepository(); // blaze it
     Ore target = redisOre.ReadOre((int)oreId);
     return View(target);
 }
示例#3
0
        public ActionResult Comment(string comment, int id)
        {
            RedisUserRepository redisUser = new RedisUserRepository();
            RedisOreRepository redisOre = new RedisOreRepository();
            RedisCommentRepository redisComment = new RedisCommentRepository();
            Ore parentOre = redisOre.ReadOre(id);

            if (Context.Session.GetString("user") == null)
            {
                return RedirectToAction("Login", "Community");
            }
            User author = JsonConvert.DeserializeObject<User>(Context.Session.GetString("user"));

            List<string> validation = new List<string>();
            if (comment == null)
            {
                validation.Add("Please enter your comment");
            }
            if (id == 0)
            {
                return RedirectToAction("Index", "Ore");
            }
            ViewData["validationSummary"] = validation;

            if(!validation.Any())
            {
                Comment target = new Comment();
                target.Content = comment;
                target.Author = author.UserName;
                target.ParentOre = parentOre.Name;
                redisComment.CreateComment(target);

                if(author.CommentsAuthored != null)
                {
                    author.CommentsAuthored.Add(target.Id);
                    redisUser.UpdateUser(author);
                }
                else
                {
                    List<int> commentsAuthored = new List<int>();
                    commentsAuthored.Add(target.Id);
                    author.CommentsAuthored = commentsAuthored;
                    redisUser.UpdateUser(author);
                }

                if(parentOre.Comments != null)
                {
                    parentOre.Comments.Add(target.Id);
                    redisOre.UpdateOre(parentOre);
                }
                else
                {
                    List<int> comments = new List<int>();
                    comments.Add(target.Id);
                    parentOre.Comments = comments;
                    redisOre.UpdateOre(parentOre);
                }
            }

            ViewData["commentSuccess"] = true;
            return View("Info", parentOre);
        }