public ActionResult GetAllSubreddits(SubRedditsVM model, int?userId) { SubRedditsRepository repo = new SubRedditsRepository(); if (userId == null) { model.SubRedditsList = repo.GetAll(null); } else { model.SubRedditsList = repo.GetAll(x => x.SubscribedUsers.Any(b => b.Id == userId)).ToList(); } return(View(model)); }
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); SubRedditsRepository repo = new SubRedditsRepository(); PostsRepository postsRepository = new PostsRepository(); UsersRepository usersRepository = new UsersRepository(); List <SubReddit> items = repo.GetAll(null); List <Post> posts = postsRepository.GetAll(null); List <User> users = usersRepository.GetAll(null); foreach (SubReddit sr in items) { routes.MapRoute( name: "SubReddit" + sr.Id, url: "r/" + sr.Name, defaults: new { controller = "Posts", action = "Index", SubRedditId = sr.Id }); /*foreach (Post item in posts.Where(a => a.SubRedditId==sr.Id)) * { * routes.MapRoute( * name: "Post" + item.Id, * url: "r/" + sr.Name +"/" + "comments"+ '/' + getTitleForURL(item.Title.ToLower()), * defaults: new { controller = "Comments", action = "Index", PostId = item.Id }); * }*/ } foreach (User item in users) { routes.MapRoute( name: "Profile" + item.Id, url: "user/" + item.Username, defaults: new { controller = "Profile", action = "Index", UserId = item.Id } ); } /*foreach (var item in Reddit.Models.AuthManager.LoggedUser.SubscribedToSubReddits) * { * routes.MapRoute( * name: "Something" , * url: "r/" + item.Name + "/submit", * defaults: new { controller = "Posts", action = "Create", id = UrlParameter.Optional } * ); * } * * string allOrHome = ""; * if (Reddit.Models.AuthManager.LoggedUser != null) allOrHome = "r/home"; * else allOrHome = "r/all"; * routes.MapRoute( * name: "allHome", * url: allOrHome, * defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } * );*/ routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); }
public ActionResult Search(SearchVM model, int?postId, int?subredditId) { model.SubReddits = new List <SubReddit>(); model.Users = new List <User>(); SubRedditsRepository subRepo = new SubRedditsRepository(); PostsRepository postRepo = new PostsRepository(); UsersRepository userRepo = new UsersRepository(); List <SubReddit> subs = subRepo.GetAll(a => a.Name.Contains(model.Filter)).OrderByDescending(a => a.SubscribedUsers.Count()).ToList(); List <User> users = userRepo.GetAll(a => a.Username.Contains(model.Filter)).OrderByDescending(a => a.Karma).ToList(); // model.SubReddits = subRepo.GetAll(a => a.Name.Contains(model.Filter)).ToList(); var count = 0; Thread ta = new Thread(new ThreadStart(UsersLoop)); Thread tb = new Thread(new ThreadStart(SubLoop)); ta.Start(); tb.Start(); ta.Join(); tb.Join(); void UsersLoop() { Thread.Sleep(400); foreach (var item in users) { if (count == 3) { break; } model.Users.Add(item); count++; } } void SubLoop() { Thread.Sleep(390); foreach (var item in subs) { if (count == 3) { break; } model.SubReddits.Add(item); count++; } } model.Posts = postRepo.GetAll(a => a.Title.ToLower().Contains(model.Filter.ToLower()) || a.SubReddit.Name.ToLower().Contains(model.Filter.ToLower()) || a.Comments.Any(b => b.Text.ToLower().Contains(model.Filter.ToLower())) || a.Content.ToLower().Contains(model.Filter.ToLower())).OrderByDescending(b => b.Rating).ToList(); return(View(model)); }
public ActionResult Index() { PostIndexVM model = new PostIndexVM(); PostsRepository repo = new PostsRepository(); SubRedditsRepository subRedditsRepository = new SubRedditsRepository(); model.Posts = repo.GetAll(p => p.IsApproved == true).OrderByDescending(a => a.Rating).ToList(); model.TrendingSubReddits = subRedditsRepository.GetAll(null); if (AuthManager.LoggedUser != null) { model.SubReddits = subRedditsRepository.GetAll(null) .Where(x => x.SubscribedUsers.Any(b => b.Id == AuthManager.LoggedUser.Id)).OrderByDescending(c => c.Id).ToList(); } else { model.SubReddits = subRedditsRepository.GetAll(null); } return(View(model)); }