コード例 #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
ファイル: 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);
        }