コード例 #1
0
ファイル: ModeratorSqlDAO.cs プロジェクト: baesilx/NightCap
        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);
        }
コード例 #2
0
ファイル: PostSqlDAO.cs プロジェクト: baesilx/NightCap
 public Post AddPost(Post post)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.Posts.Add(post);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(post);
 }
コード例 #3
0
 public FavoriteForum AddFavorite(FavoriteForum favoriteForum)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.FavoriteForums.Add(favoriteForum);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(favoriteForum);
 }
コード例 #4
0
ファイル: VoteSqlDAO.cs プロジェクト: baesilx/NightCap
 public Vote AddVote(Vote vote)
 {
     try
     {
         using (NightCapDBContext nightCapDBContext = new NightCapDBContext())
         {
             nightCapDBContext.Votes.Add(vote);
             nightCapDBContext.SaveChanges();
         }
     }
     catch (SqlException)
     {
         throw;
     }
     return(vote);
 }
コード例 #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
ファイル: PostSqlDAO.cs プロジェクト: baesilx/NightCap
 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);
 }
コード例 #7
0
ファイル: PostSqlDAO.cs プロジェクト: baesilx/NightCap
        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);
        }
コード例 #8
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);
        }