예제 #1
0
        /// <summary>
        /// DBから取得する処理
        /// </summary>
        /// <param name="skipCount">スキップする要素数</param>
        /// <param name="takeCount">返す要素数</param>
        /// <returns>FollowingMemberForUserのIEnumerableオブジェクト</returns>
        private void SetLines(UserFollowersViewModel viewModel, long other_member_id, int skipCount, int takeCount)
        {
            List<FollowerMemberForUser> followerMembers = new List<FollowerMemberForUser> { };

            try
            {

                if (other_member_id > 0)
                {
                    //FollowListテーブルからフォロワーの一覧を取得(f1)
                    //自分のMemberIdでFollowListテーブルのMemberIdを検索し、ProfileImgとNicknameを読み出す(m)

                    //FollowListテーブルから自分がフォローしているユーザーの一覧を取得(f2)
                    //該当行のユーザーをフォローしている場合、「フォロー中」を表示、そうでない場合は「フォローする」を表示する
                    var lines = from f1 in com.FollowList
                                join m in com.Member on f1.FollowerMemberID equals m.MemberId
                                where f1.MemberID == other_member_id
                                select new FollowerMemberForUser
                                {
                                    MemberId = f1.FollowerMemberID,
                                    Nickname = m.Nickname,
                                    ProfileImg = m.ProfileImg,
                                };

                    //合計数
                    viewModel.TotalCount = lines.Count();

                    //FollowListテーブルからフォロワーの一覧を取得
                    //フォロワーのMemberIdでPointテーブルから付与対象年月が現在月となるPointを抽出、
                    //さらにそれらに紐づく精算済みポイントを抽出し精算済ポイントフィールドを合算する。
                    //3で抽出したPointのPointIdでExpectedPointテーブルを検索し、
                    //日付のもっとも新しいものの登録日時を取得し、フォーマットに合わせて出力する

                    int year = DateTime.Now.Year;
                    int month = DateTime.Now.Month;

                    string query = "SELECT MemberID," +
                                    "       ISNULL(SUM(PayOffPoints), 0) AS PayOffPoints," +
                                    "       ISNULL(SUM(fundspoint), 0) AS FundsPoint," +
                                    "       ISNULL(SUM(possesionpoint), 0) AS PossesionPoint," +
                                    "       MAX(ExpectPoint_CreatedDate) AS LastExpectedPointDate " +
                                    "FROM [Splg].[Com].[Point] p " +
                                    "LEFT JOIN" +
                                    "  (SELECT PointID," +
                                    "          MAX(CreatedDate) AS ExpectPoint_CreatedDate" +
                                    "   FROM [Splg].[Com].[ExpectPoint]" +
                                    "   GROUP BY PointID) e ON p.PointID = e.PointID " +
                                    "WHERE " +
                                    "  p.GiveTargetYear =  " + year +
                                    "  AND p.GiveTargetMonth = " + month +
                                    "  AND p.MemberID IN" +
                                    "    (SELECT FollowerMemberID" +
                                    "     FROM [Splg].[Com].[FollowList]" +
                                    "     WHERE MemberID = " + other_member_id + ")" +
                                    " GROUP BY p.memberid";

                    var pointDatas = com.Database.SqlQuery<FollowerMemberForUser>(@query).ToList < FollowerMemberForUser>();

                    long loginMemberId = 0;

                    object currentUser = Session["CurrentUser"];
                    if (currentUser != null)
                        loginMemberId = Convert.ToInt64(currentUser.ToString());

                    foreach (FollowerMemberForUser m in lines)
                    {
                        //フォロワーリストに対して、ログインユーザーのフォロー状況を判別
                        m.IsFollowing = GetIsFollowing(loginMemberId, m.MemberId);

                        var p = pointDatas.SingleOrDefault(x => x.MemberId == m.MemberId);

                        if (p != null && p.MemberId != 0)
                        {
                                m.PayOffPoints = p.PayOffPoints;
                                m.FundsPoint = p.FundsPoint;
                                m.PossesionPoint = p.PossesionPoint;
                                m.LastExpectedPointDate = p.LastExpectedPointDate;
                        }

                        m.IsLoginUser = (m.MemberId == loginMemberId);

                        //m.PayOffPoints = new Random().Next();  //debug
                        followerMembers.Add(m);

                    }

                    //当月の精算済みポイント合計で降順にする
                    var result =  from m in followerMembers orderby m.PayOffPoints descending select m;

                    //表示分読み込む
                    viewModel.FollowerMembers = result.Skip(skipCount).Take(takeCount);

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        /// <summary>
        /// ViewModelを取得
        /// </summary>
        /// <param name="targetMemberId">他ユーザの会員ID</param>
        /// <param name="loginMemberId">ログインユーザの会員ID</param>
        /// <param name="skipCount">スキップする要素数</param>
        /// <param name="takeCount">返す要素数</param>
        /// <param name="targetYear">付与対象年</param>
        /// <param name="targetMonth">付与対象月</param>
        /// <returns>UserFollowersViewModelオブジェクト</returns>
        public UserFollowersViewModel GetViewModel(long targetMemberId, long loginMemberId, int skipCount, int takeCount, int targetYear, int targetMonth)
        {
            // 対象ユーザの会員情報を取得
            var targetMember = this.dbContext.Member.FirstOrDefault(x => x.MemberId == targetMemberId);
            if (targetMember == null)
            {
                return null;
            }

            // フォロワーの一覧を取得
            var followers = this.followInfoService.GetFollowerMembers(targetMemberId).ToArray();

            // フォロワーのポイント情報を取得
            this.pointService.GetMembersWithOnlinePoints(followers, targetYear, targetMonth);

            //フォロワーリストに対して、ログインユーザーのフォロー状況を判別
            followers.ForEach(f => f.IsFollowing = this.IsFollowing(f.MemberId, loginMemberId));
            followers.ForEach(f => { f.IsLoginUser = f.MemberId == loginMemberId; });

            // 当月の精算済みポイント合計で降順にする
            // 表示分読み込む
            var targetFollowers = followers.OrderByDescending(x => x.PayOffPoints)
                                           .Skip(skipCount)
                                           .Take(takeCount);

            // InfoModelへ変換
            var followerInfoModels = this.ConvertToInfoModel(targetFollowers);

            // 対象ユーザのメンバー情報を設定
            var viewModel = new UserFollowersViewModel
            {
                MemberId = targetMember.MemberId,
                Nickname = targetMember.Nickname,
                TotalCount = followers.Count(),
                FollowerMembers = followerInfoModels
            };

            return viewModel;
        }