public void CreateComment(Comment comment) { using (var pooledRedisClient = new PooledRedisClientManager()) using (var redis = pooledRedisClient.GetClient()) { var redisComment= redis.As<Comment>(); if(comment.Id == 0) { comment.Id = (int)redisComment.GetNextSequence(); } redisComment.Store(comment); } }
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); }