public void DeleteOre(int oreId) { RedisUserRepository redisUser = new RedisUserRepository(); using (var pooledRedisClient = new PooledRedisClientManager()) using (var redis = pooledRedisClient.GetClient()) { var redisOre = redis.As<Ore>(); Ore inquestion = redis.GetById<Ore>(oreId); User author = redisUser.ReadUser(inquestion.AuthorId); author.OresAuthored.Remove(inquestion.Name); // We can assume the list is populated because we have an ore to delete redisUser.UpdateUser(author); redisOre.DeleteById(oreId); // Delete ore using ID redis.RemoveEntry(inquestion.Name + ":id"); var set = redis.Sets["Ores"]; set.Remove(inquestion.Name); } }
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) }); }
public ActionResult UnlikeC(int? comment, int? user) { RedisUserRepository redisUser = new RedisUserRepository(); RedisCommentRepository redisComment = new RedisCommentRepository(); RedisOreRepository redisOre = new RedisOreRepository(); if (comment == null || user == null) { return RedirectToAction("Index", "Ore"); } if (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); Comment target = redisComment.ReadComment((int)comment); if (author.CommentsLiked.Contains((int)comment)) { target.Likes -= 1; redisComment.CreateComment(target); // Will overwrite the comment already in the db author.CommentsLiked.Remove((int)comment); redisUser.UpdateUser(author); } ViewData["commentSuccess"] = false; Context.Session.SetString("user", JsonConvert.SerializeObject(author)); return RedirectToAction("Info", "Ore", new { oreName = redisOre.ReadName(target.ParentOre).Name }); }