Exemplo n.º 1
0
        public JsonResult AddGroup(MyPageGroupNewViewModel.AddGroupModel addGroupModel)
        {
            long loginMemberId = GetLoginMemberId();

            var group_name = addGroupModel.GroupName;

            try
            {
                /////////////////////////////////////////////////////////
                //入力チェック
                if (loginMemberId <= 0 && String.IsNullOrEmpty(group_name) )
                {

                    addGroupModel.ErrorMessage = "グループを作成できません。";
                    return Json(addGroupModel, JsonRequestBehavior.AllowGet);
                }

                var group = (from g in com.Groups
                                   where g.GroupName == group_name
                                   && g.MemberID == loginMemberId
                                    && g.Status == true
                                    select g).FirstOrDefault();

                if (group != null)
                {
                    addGroupModel.ErrorMessage = "同じ名前のグループがすでにあります。";
                    return Json(addGroupModel, JsonRequestBehavior.AllowGet);
                }

                /////////////////////////////////////////////////////////
                //新規グループを作成する
                var newGroup = new Groups
                {
                    GroupName = group_name,
                    MemberID = loginMemberId,
                    Status = true,             // 0・・無効 1・・有効
                    CreatedAccountID = loginMemberId.ToString()
                };
                com.Groups.Add(newGroup);
                com.SaveChanges();
                var group_id = (from g in com.Groups
                                where g.GroupName == group_name
                                &&
                                g.MemberID == loginMemberId
                                select g.GroupID).FirstOrDefault();

                addGroupModel.GroupID = Convert.ToInt32(group_id);

                /////////////////////////////////////////////////////////
                //グループメンバーの更新
                using (var dbContextTransaction = com.Database.BeginTransaction())
                {
                    try
                    {
                        if (addGroupModel.MemberIDs == null)
                        {
                            addGroupModel.MemberIDs = new List<long>();
                        }

                        //メンバーに自身を追加
                        addGroupModel.MemberIDs.Add(loginMemberId);

                        //通知メールのタイトルと本文を取得
                        NoticeInfo noticeInfo = (from ni in com.NoticeInfo
                                                 where ni.MailDelivCondID == 4 && ni.NoticeClass == 3
                                                 select ni).FirstOrDefault();
                        string title = noticeInfo.Title;
                        string body = noticeInfo.Body;

                        //追加メンバーの一覧からグループメンバーを新規作成
                        foreach (var newMemberId in addGroupModel.MemberIDs)
                        {
                            var newGroupMember = new GroupMember
                            {
                                GroupID = group_id,
                                MemberID = newMemberId,
                                CreatedAccountID = loginMemberId.ToString(),
                                CreatedDate = DateTime.Now

                            };
                            com.GroupMember.Add(newGroupMember);

                            //新規に追加する会員向けにメール通知
                            if (loginMemberId == newMemberId)
                                continue;

                            //追加する会員向けにメール通知
                            NoticeInfoForMyPage notice = new NoticeInfoForMyPage();

                            notice.ClassClass = NoticeInfoForMyPage.CLS_GROUP;
                            notice.AddGroup = (from gm in com.Member where gm.MemberId == loginMemberId select gm.Nickname).FirstOrDefault();
                            notice.GroupID = group_id.ToString();
                            notice.Group = (from g in com.Groups where g.GroupID == group_id select g.GroupName).FirstOrDefault();
                            notice.Nickname = (from gm in com.Member where gm.MemberId == loginMemberId select gm.Nickname).FirstOrDefault();

                            notice.setTitle(NoticeInfoForMyPage.CLS_GROUP, title);
                            notice.setBody(NoticeInfoForMyPage.CLS_GROUP, body);

                            MyPageCommon.SendMail(newMemberId, notice.Title, notice.Body);

                            //新規に追加する会員向けにお知らせ配信対象を生成
                            var newNotice = new NoticeDeliverySubject
                            {
                                NoticeId = Convert.ToInt32(noticeInfo.NoticeId),
                                MemberId = Convert.ToInt32(newMemberId),
                                ClassClass = 7,
                                UniqueID = Convert.ToInt32(loginMemberId),  //グループに入れた会員IDを保存
                                UniqueID2 = Convert.ToInt32(group_id),
                                AlreadyReadFlg = false,
                                NoticeDeliveryStatus = 1,
                                CreatedAccountID = loginMemberId.ToString(),
                                CreatedDate = DateTime.Now
                            };
                            com.NoticeDeliverySubject.Add(newNotice);

                        }
                        com.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return Json(addGroupModel, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 他の会員をフォローする
        /// </summary>
        /// <param name="followerMemberId">フォローする会員(ログインユーザ)</param>
        /// <param name="followingMemberId">フォローされる会員</param>
        public static void follow(long followerMemberId, long followingMemberId)
        {
            try
            {
                if (followerMemberId <= 0)
                    throw new Exception("フォローする側の会員IDが不正です。");

                if (followingMemberId <= 0)
                    throw new Exception("フォローされる側の会員IDが不正です。");

                if (followerMemberId == followingMemberId)
                    throw new Exception("フォローする側とされる側の会員IDが同じです。");

                using (ComEntities com = new ComEntities())
                {
                    using (var dbContextTransaction = com.Database.BeginTransaction())
                    {
                        try
                        {
                            FollowList f = new FollowList
                            {
                                MemberID = followingMemberId,
                                FollowerMemberID = followerMemberId,
                                CreatedDate = DateTime.Now
                            };

                            com.FollowList.Add(f);

                            com.SaveChanges();

                            //お知らせ配信対象(NoticeDeliverySubject)テーブルにメール送信対象データを登録する。

                            var noticeId = (from ni in com.NoticeInfo
                                            where ni.MailDelivCondID == 3
                                            select ni.NoticeId).FirstOrDefault();

                            NoticeDeliverySubject nds = new NoticeDeliverySubject
                            {
                                NoticeId = (int)noticeId,               //お知らせ(NoticeInfo)のMailDelivCondID = 3 のレコードのお知らせID(NoticeId)を設定
                                MemberId = (int)followingMemberId,       //フォローされた会員ID
                                ClassClass = 6,                         //フォロー
                                UniqueID = (int)followerMemberId,      //ログインユーザの会員ID
                                AlreadyReadFlg = false,
                                NoticeDeliveryStatus = 1,
                                CreatedAccountID = followerMemberId.ToString(),
                                CreatedDate = DateTime.Now
                            };

                            if (nds != null)
                            {
                                com.NoticeDeliverySubject.Add(nds);
                                com.SaveChanges();
                            }

                            NoticeInfo noticeInfo = (from ni in com.NoticeInfo
                                                     where ni.MailDelivCondID == 3 && ni.NoticeClass == 3
                                                     select ni).FirstOrDefault();
                            string title = noticeInfo.Title;
                            string body = noticeInfo.Body;

                            NoticeInfoForMyPage notice = new NoticeInfoForMyPage();

                            notice.ClassClass = NoticeInfoForMyPage.CLS_FOLLOW;
                            notice.MemberId = (int)followerMemberId;
                            notice.Follower = (from m in com.Member where m.MemberId == followerMemberId select m.Nickname).FirstOrDefault();
                            notice.Follow = (from m in com.Member where m.MemberId == followingMemberId select m.Nickname).FirstOrDefault();

                            notice.setTitle(NoticeInfoForMyPage.CLS_FOLLOW, title);
                            notice.setBody(NoticeInfoForMyPage.CLS_FOLLOW, body);

                            Splg.Areas.MyPage.MyPageCommon.SendMail(followingMemberId, notice.Title, notice.Body);

                            dbContextTransaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            dbContextTransaction.Rollback();
                            throw ex;
                        }

                    }

                }

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public JsonResult UpdateGroup(MyPageGroupEditViewModel.AddGroupModel addGroupModel)
        {
            long loginMemberId = GetMemberID();

            var group_id = addGroupModel.GroupID;

            try
            {
                /////////////////////////////////////////////////////////
                //入力チェック
                if (loginMemberId <= 0 && group_id <= 0)
                {
                    addGroupModel.ErrorMessage = "グループを編集できません。";
                    return Json(addGroupModel, JsonRequestBehavior.AllowGet);
                }

                var group = (from g in com.Groups
                                    where g.GroupID == group_id
                                    select g).FirstOrDefault();
                if (group == null)
                {
                    addGroupModel.ErrorMessage = "グループがありません。";
                    return Json(addGroupModel, JsonRequestBehavior.AllowGet);
                }

                /////////////////////////////////////////////////////////
                //グループ情報を更新する
                group.GroupName = addGroupModel.GroupName;
                group.ModifiedAccountID = loginMemberId.ToString();
                group.ModifiedDate = DateTime.Now;

                /////////////////////////////////////////////////////////
                //グループメンバーの更新
                using (var dbContextTransaction = com.Database.BeginTransaction())
                {
                    try
                    {

                        //既存メンバーを一旦削除
                        //TODO 将来削除対象のみ削除するように変更
                        var existingMembers = from g in com.GroupMember
                                        where g.GroupID == group_id
                                        select g;

                        foreach (var gm in existingMembers)
                        {
                            com.GroupMember.Remove(gm);
                        }

                        com.SaveChanges();

                        //メンバーに自身を追加
                        if (addGroupModel.MemberIDs == null)
                            addGroupModel.MemberIDs = new List<long> { };

                        if (!addGroupModel.MemberIDs.Contains(loginMemberId))
                            addGroupModel.MemberIDs.Add(loginMemberId);

                        //通知メールのタイトルと本文を取得
                        NoticeInfo noticeInfo = (from ni in com.NoticeInfo
                                                    where ni.MailDelivCondID == 4 && ni.NoticeClass == 3
                                                    select ni).FirstOrDefault();
                        string title = noticeInfo.Title;
                        string body = noticeInfo.Body;

                        //追加メンバーの一覧からグループメンバーを新規追加
                        //TODO 将来新規追加対象のみ追加するように変更
                        foreach (long newMemberId in addGroupModel.MemberIDs)
                        {
                            var newGroupMember = new GroupMember
                            {
                                GroupID = group_id,
                                MemberID = newMemberId,
                                CreatedAccountID = loginMemberId.ToString(),
                                CreatedDate = DateTime.Now

                            };
                            com.GroupMember.Add(newGroupMember);

                            //新規に追加する会員向けにメール通知
                            if (!IsNewMember(newMemberId, loginMemberId, existingMembers))
                                continue;

                            NoticeInfoForMyPage notice = new NoticeInfoForMyPage();

                            notice.ClassClass = NoticeInfoForMyPage.CLS_GROUP;
                            notice.AddGroup = (from gm in com.Member where gm.MemberId == loginMemberId select gm.Nickname).FirstOrDefault();
                            notice.GroupID = group_id.ToString();
                            notice.Group = (from g in com.Groups where g.GroupID == group_id select g.GroupName).FirstOrDefault();
                            notice.Nickname = (from gm in com.Member where gm.MemberId == loginMemberId select gm.Nickname).FirstOrDefault();

                            notice.setTitle(NoticeInfoForMyPage.CLS_GROUP, title);
                            notice.setBody(NoticeInfoForMyPage.CLS_GROUP, body);

                            MyPageCommon.SendMail(newMemberId, notice.Title, notice.Body);

                            //新規に追加する会員向けにお知らせ配信対象を生成
                            var newNotice = new NoticeDeliverySubject
                            {
                                NoticeId = Convert.ToInt32(noticeInfo.NoticeId),
                                MemberId = Convert.ToInt32(newMemberId),
                                ClassClass = 7,
                                UniqueID = Convert.ToInt32(loginMemberId),  //グループに入れた会員IDを保存
                                UniqueID2 = Convert.ToInt32(group_id),
                                AlreadyReadFlg = false,
                                NoticeDeliveryStatus = 1,
                                CreatedAccountID = loginMemberId.ToString(),
                                CreatedDate = DateTime.Now
                            };
                            com.NoticeDeliverySubject.Add(newNotice);

                        }
                        com.SaveChanges();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception)
                    {
                        dbContextTransaction.Rollback();
                    }
                }

            }
            catch (Exception ex)
            {
                throw ex;
            }

            return Json(addGroupModel, JsonRequestBehavior.AllowGet);
        }