/// <summary> /// ViewModelを取得 /// </summary> /// <param name="newGroupModel">MyPageGroupNewViewModel.NewGroupModelオブジェクト</param> /// <param name="takeCount">返す要素数</param> /// <param name="targetYear">対象年</param> /// <param name="targetMonth">対象月</param> /// <returns>MyPageFollowingViewModelオブジェクト</returns> public MyPageGroupNewViewModel GetViewModel(MyPageGroupNewViewModel.NewGroupModel newGroupModel, int takeCount, int targetYear, int targetMonth) { if (newGroupModel == null) return new MyPageGroupNewViewModel(); var groupMembers = newGroupModel.GroupMembers; if (newGroupModel.GroupMemberIdList == null) { // グループメンバ情報を取得 groupMembers = this.groupInfoService.GetGroupMembers(newGroupModel.GroupId, newGroupModel.MemberId) .Select(g => new MemberModel { MemberId = g.MemberId, Nickname = g.Nickname, ProfileImg = g.ProfileImg, IsLoginUser = g.IsLoginUser }) .OrderBy(x => x.MemberId) .ToList(); // グループメンバのポイント情報を取得 this.pointInfoService.GetMembersWithOnlinePoints(groupMembers.ToArray(), targetYear, targetMonth); } // フォローメンバ情報を取得 newGroupModel.FollowerSearchString = newGroupModel.FollowerSearchString ?? string.Empty; var followingMembers = this.followInfoService.GetFollowingMembers(newGroupModel.MemberId, newGroupModel.FollowerSearchString).ToArray(); // フォローメンバのポイント情報を取得 this.pointInfoService.GetMembersWithOnlinePoints(followingMembers, targetYear, targetMonth); // フォローメンバからグループメンバを除く List<MemberModel> notInGroupMembers; if (newGroupModel.GroupMemberIdList == null) { notInGroupMembers = followingMembers.Where(x => !(groupMembers.Select(y => y.MemberId)).Contains(x.MemberId)).ToList(); } else { notInGroupMembers = followingMembers.Where(x => !(newGroupModel.GroupMemberIdList).Contains(x.MemberId)).ToList(); } // 追加対象のフォローメンバを取得 List<MemberModel> targetFollowingMembers; if (newGroupModel.FollowMemberIdList != null) { // 編集画面上ですでに表示されているメンバを除く targetFollowingMembers = notInGroupMembers.Where(x => !(newGroupModel.FollowMemberIdList).Contains(x.MemberId)) .Take(takeCount) .ToList(); } else { targetFollowingMembers = notInGroupMembers.Take(takeCount).ToList(); } // ViewModelへ設定 var viewModel = new MyPageGroupNewViewModel { NewGroup = newGroupModel }; viewModel.NewGroup.GroupMembers = groupMembers; viewModel.NewGroup.FollowMembers = targetFollowingMembers; viewModel.TotalCount = notInGroupMembers.Count; return viewModel; }
public JsonResult SearchMember(MyPageGroupNewViewModel.NewGroupModel newGroup) { long memberId = GetLoginMemberId(); MyPageGroupNewViewModel viewModel = new MyPageGroupNewViewModel(); if (newGroup != null) { viewModel.NewGroup = newGroup; } else { viewModel.NewGroup = new MyPageGroupNewViewModel.NewGroupModel { GroupId = 0, GroupName = String.Empty, FollowerSearchString = String.Empty, GroupMembers = new List<MemberModel>(), FollowMembers = new List<MemberModel>(), GroupMemberIdList = null }; } viewModel.NewGroup.MemberId = memberId; viewModel = this.workerService.GetViewModel(viewModel.NewGroup, MyPageGroupEditViewModel.INITIAL_PAGE_SIZE, this.systemDatetimeService.TargetYear, this.systemDatetimeService.TargetMonth); //GetFollowingMember(viewModel); return Json(viewModel, JsonRequestBehavior.AllowGet); }
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); }
/// <summary> /// GET: /mypage/group/new /// </summary> public ActionResult Index() { //Todo:認証処理 AOPでやりたい。 一旦Session変数を参照し判定 if (Session["CurrentUser"] == null) { return RedirectToActionPermanent("Login", "Member", new { area = "" }); } var viewModel = new MyPageGroupNewViewModel(); long memberId = this.GetLoginMemberId(); if (memberId <= 0) return View(viewModel); viewModel.NewGroup = new MyPageGroupNewViewModel.NewGroupModel(); viewModel.NewGroup.MemberId = memberId; viewModel.NewGroup.GroupId = 0; viewModel.NewGroup.GroupName = ""; viewModel.NewGroup.FollowerSearchString = ""; viewModel = this.workerService.GetViewModel(viewModel.NewGroup, MyPageGroupEditViewModel.INITIAL_PAGE_SIZE, this.systemDatetimeService.TargetYear, this.systemDatetimeService.TargetMonth); return View(viewModel); }