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 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);
 }
 public ActionResult Search(string searchParam)
 {
     RedisOreRepository redisOre = new RedisOreRepository();
     return View(redisOre.NameContains(searchParam).ToArray());
 }
 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 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);
        }
 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(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 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 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");
     }
 }