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 });
 }
 public ActionResult Info(string oreName)
 {
     if(oreName == null)
     {
         return RedirectToAction("Index", "Ore");
     }
     RedisOreRepository oreRepo = new RedisOreRepository();
     Ore target = oreRepo.ReadName(oreName);
     ViewData["commentSuccess"] = false;
     return View(target);
 }
 public ActionResult Edit(string oreName)
 {
     RedisUserRepository userRepo = new RedisUserRepository();
     RedisOreRepository oreRepo = new RedisOreRepository();
     if (Context.Session.GetString("user") != null)
     {
         if (oreName != null)
         {
             Ore ore = oreRepo.ReadName(oreName);
             User user = JsonConvert.DeserializeObject<User>(Context.Session.GetString("user"));
             if (user.OresAuthored.Contains(ore.Name))
             {
                 return View(ore); // If there is an ore name and author is able to edit
             }
             else
             {
                 return RedirectToAction("Index", "Ore"); // If they do not have permissions send them to the index
             }
         }
         else { return View(new Ore()); } // If there is no ore specified return a new ore
     }
     return RedirectToAction("Login", "Community"); // If no user is logged in, log somebody in
 }
 public ActionResult Edit(Ore ore)
 {
     RedisUserRepository redisUser = new RedisUserRepository();
     RedisOreRepository redisOre = new RedisOreRepository();
     User author = JsonConvert.DeserializeObject<User>(Context.Session.GetString("user"));
     // Validation Checks
     List<string> validation = new List<string>();
     if (ore.Name == null)
     {
         validation.Add("Please name your ore");
     }
     if (ore.Description == null)
     {
         validation.Add("Please set a description of your ore");
     }
     if (redisOre.ReadName(ore.Name) != null) // If the name is used in the database
     {
         if(author.OresAuthored != null) // If the author has authored ores
         {
             if (!author.OresAuthored.Contains(ore.Name)) // Ores Authored is populated but does not contain the ore
             {
                 validation.Add("You do not have permission to edit this ore");
             } // No else because if the author.OresAuthored contains the ore, it's good to go
         }
         else // Ores Authored is empty
         {
             validation.Add("You do not have permission to edit this ore");
         }
     }
     ViewData["validationSummary"] = validation;
     if (!validation.Any())
     {
         if(ore.Comments == null)
         {
             List<int> comments = new List<int>();
             ore.Comments = comments;
         }
         // Save ore to DB
         ore.AuthorId = author.Id;
         redisOre.UpdateOre(ore);
         if (author.OresAuthored == null)
         {
             List<string> list = new List<string>();
             list.Add(ore.Name);
             author.OresAuthored = list;
         }
         else
         {
             if(!author.OresAuthored.Contains(ore.Name))
             {
                 author.OresAuthored.Add(ore.Name); // If the ore isn't already in the author's list
             }
         }
         redisUser.UpdateUser(author);
         // Save ore to App Data
         return RedirectToAction("Profile", "Community");
     }
     else
     {
         // Model is not valid, return view to the user
         return View(ore);
     }
 }
 public ActionResult Delete(string oreName)
 {
     // Add extra deletes
     RedisOreRepository redisOre = new RedisOreRepository();
     Ore target = redisOre.ReadName(oreName);
     if (Context.Session.GetString("user") != null)
     {
         User author = JsonConvert.DeserializeObject<User>(Context.Session.GetString("user"));
         if(target.AuthorId == author.Id)
         {
             redisOre.DeleteOre(target.Id);
             author.OresAuthored.Remove(target.Name);
             return RedirectToAction("Profile", "Community");
         }
         else
         {
             return RedirectToAction("Index");
         }
     }
     else
     {
         return RedirectToAction("Login", "Community");
     }
 }