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 Post AddPost(Post post) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Posts.Add(post); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(post); }
public FavoriteForum AddFavorite(FavoriteForum favoriteForum) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.FavoriteForums.Add(favoriteForum); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(favoriteForum); }
public Vote AddVote(Vote vote) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Votes.Add(vote); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(vote); }
public Comment AddComment(Comment comment) { try { using (NightCapDBContext nightCapDBContext = new NightCapDBContext()) { nightCapDBContext.Comments.Add(comment); nightCapDBContext.SaveChanges(); } } catch (SqlException) { throw; } return(comment); }
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 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 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); }