public List <Forum> GetFavorites(int userId) { ForumSqlDAO forumSqlDAO = new ForumSqlDAO(connectionString); List <FavoriteForum> favoriteForums = new List <FavoriteForum>(); List <Forum> forumList = new List <Forum>(); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { favoriteForums = nightCapDBContext.FavoriteForums.Where(f => f.UserId == userId).ToList(); foreach (FavoriteForum forum in favoriteForums) { forumList.Add(forumSqlDAO.GetForumById(forum.ForumId)); } } } catch (SqlException) { throw; } return(forumList); }
public Moderator AddModerator(int userID, string username, string forumName) { Moderator moderator; ForumSqlDAO forumSqlDAO = new ForumSqlDAO(connectionString); Forum forum = forumSqlDAO.GetForumByName(forumName); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { moderator = new Moderator() { UserId = userID, Username = username, ForumName = forumName }; if (!IsModerator(moderator.UserId, forum.ID)) { nightCapDBContext.Moderators.Add(moderator); nightCapDBContext.SaveChanges(); } } } catch (SqlException) { throw; } return(moderator); }
public Vote AddVote(Vote vote) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Votes.Add(vote); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(vote); }
public Post AddPost(Post post) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Posts.Add(post); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(post); }
public Comment AddComment(Comment comment) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Comments.Add(comment); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(comment); }
public FavoriteForum AddFavorite(FavoriteForum favoriteForum) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.FavoriteForums.Add(favoriteForum); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(favoriteForum); }
public List <Vote> GetVotesByPost(int postId) { List <Vote> votes = new List <Vote>(); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { votes = nightCapDBContext.Votes.Where(v => v.PostId == postId).ToList(); } } catch (SqlException) { throw; } return(votes); }
public Forum GetForumById(int forumID) { Forum forum; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { forum = nightCapDBContext.Forums.Where <Forum>(f => f.ID == forumID).SingleOrDefault(); } } catch (SqlException) { throw; } return(forum); }
public Post AddImage(Post post) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { Post updatedPost = nightCapDBContext.Posts.Single <Post>(p => p.ID == post.ID); updatedPost.IMG_URL = post.IMG_URL; nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(post); }
public Moderator GetModerator(string forumName) { Moderator moderator; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { moderator = nightCapDBContext.Moderators.Where <Moderator>(m => m.ForumName == forumName).SingleOrDefault(); } } catch (SqlException) { throw; } return(moderator); }
public List <Comment> ListCommentsByPost(int postId) { List <Comment> comments = new List <Comment>(); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { comments = nightCapDBContext.Comments.Where(c => c.PostId == postId).ToList(); } } catch (SqlException) { throw; } return(comments); }
public List <Forum> ListForums() { List <Forum> forumList; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { forumList = nightCapDBContext.Forums.ToList(); } } catch (SqlException) { throw; } return(forumList); }
public List <Post> ListPosts() { List <Post> posts; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { posts = nightCapDBContext.Posts.ToList(); } } catch (SqlException) { throw; } return(posts); }
public Forum GetForumByName(string name) { Forum forum; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { forum = nightCapDBContext.Forums.Where <Forum>(f => f.Title == name).SingleOrDefault(); } } catch (SqlException) { throw; } return(forum); }
public Post GetPost(int postID) { Post post; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { post = nightCapDBContext.Posts.Where <Post>(f => f.ID == postID).SingleOrDefault(); } } catch (SqlException) { throw; } return(post); }
public List <Post> ListPostsByForum(int forumId) { List <Post> forumPosts = new List <Post>(); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { forumPosts = nightCapDBContext.Posts.Where(p => p.ForumId == forumId).ToList(); } } catch (SqlException) { throw; } return(forumPosts); }
public bool IsModerator(int userId, int forumId) { bool isMod = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (nightCapDBContext.Moderators.Any(m => m.UserId == userId && m.ForumId == forumId)) { isMod = true; } } } catch (SqlException) { throw; } return(isMod); }
public bool DeleteComment(int commentId) { bool isDeleted = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { Comment comment = nightCapDBContext.Comments.Find(commentId); nightCapDBContext.Remove(comment); nightCapDBContext.SaveChanges(); isDeleted = true; } } catch (SqlException) { throw; } return(isDeleted); }
public bool DoesFavoriteExist(FavoriteForum favorite) { bool doesExist = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (nightCapDBContext.FavoriteForums.Any(f => f.UserId == favorite.UserId && f.ForumId == favorite.ForumId)) { doesExist = true; } } } catch (SqlException) { throw; } return(doesExist); }
public bool DeletePost(int postId) { bool isDeleted = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { Post post = nightCapDBContext.Posts.Find(postId); nightCapDBContext.Remove(post); nightCapDBContext.SaveChanges(); isDeleted = true; } } catch (SqlException) { throw; } return(isDeleted); }
public bool DoesVotesExist(Vote newVote) { bool doesExist = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (nightCapDBContext.Votes.Any(v => v.UserId == newVote.UserId && v.PostId == newVote.PostId)) { doesExist = true; } } } catch (SqlException) { throw; } return(doesExist); }
public bool HasVoted(Vote vote) { bool hasVoted = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (DoesVotesExist(vote)) { hasVoted = true; } } } catch (SqlException) { throw; } return(hasVoted); }
public bool DoesForumExist(Forum forum) { bool doesExist = false; try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (nightCapDBContext.Forums.Any(f => f.Title == forum.Title)) { doesExist = true; } } } catch (SqlException) { throw; } return(doesExist); }
public List <Forum> GetForumBySearchString(string search) { List <Forum> forums = new List <Forum>(); search = search.ToLower(); try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { if (nightCapDBContext.Forums.Any(f => f.Title.ToLower().Contains(search) || f.Body.ToLower().Contains(search))) { forums = nightCapDBContext.Forums.Where(f => f.Title.Contains(search) || f.Body.Contains(search)).ToList(); } } } catch (SqlException) { throw; } return(forums); }