示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
 public Vote AddVote(Vote vote)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.Votes.Add(vote);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(vote);
 }
示例#4
0
 public Post AddPost(Post post)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.Posts.Add(post);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(post);
 }
示例#5
0
 public Comment AddComment(Comment comment)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.Comments.Add(comment);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(comment);
 }
示例#6
0
 public FavoriteForum AddFavorite(FavoriteForum favoriteForum)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.FavoriteForums.Add(favoriteForum);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(favoriteForum);
 }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
 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);
 }
示例#10
0
        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);
        }
示例#11
0
        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);
        }
示例#12
0
        public List <Forum> ListForums()
        {
            List <Forum> forumList;

            try
            {
                using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
                {
                    forumList = nightCapDBContext.Forums.ToList();
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(forumList);
        }
示例#13
0
        public List <Post> ListPosts()
        {
            List <Post> posts;

            try
            {
                using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
                {
                    posts = nightCapDBContext.Posts.ToList();
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(posts);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
        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);
        }
示例#22
0
        public bool HasVoted(Vote vote)
        {
            bool hasVoted = false;

            try
            {
                using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
                {
                    if (DoesVotesExist(vote))
                    {
                        hasVoted = true;
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }
            return(hasVoted);
        }
示例#23
0
        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);
        }
示例#24
0
        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);
        }