コード例 #1
0
        public ActionResult JoinDiscussionGroup(int discussionGroupID)
        {
            var group = db.DiscussionGroups.Find(discussionGroupID);
            User user = Users.GetLoggedInUser();

            if (group != null && user != null) {
                DiscussionGroupMember member = new DiscussionGroupMember();
                member.GroupID = discussionGroupID;
                member.UserID = user.UserID;
                member.GroupMembershipStatus = GroupMembershipStatus.Member;
                member.IsSubscribed = true;
                db.DiscussionGroupMembers.Add(member);

                UserAction ua = new UserAction();
                ua.SourceUserID = user.UserID;
                ua.ActionDate = DateTime.Now;
                ua.UserActionType = UserActionType.JoinDiscussionGroup;
                ua.DiscussionGroupID = discussionGroupID;
                ua.Text = "Joined " + group.Name;
                db.UserActions.Add(ua);

                db.SaveChanges();
            }

            return Json(new {success= true});
        }
コード例 #2
0
        public ActionResult InviteUserToDiscussionGroup(int userID, int discussionGroupID)
        {
            DiscussionGroupMember member = db.DiscussionGroupMembers.SingleOrDefault(dgm => dgm.GroupID == discussionGroupID && dgm.UserID == userID);

            if (member == null) {

                User inviter = Users.GetLoggedInUser();
                User invitee = Users.GetUser(userID);
                DiscussionGroup group = db.DiscussionGroups.Find(discussionGroupID);

                member = new DiscussionGroupMember();
                member.UserID = userID;
                member.GroupID = discussionGroupID;
                member.GroupMembershipStatus = GroupMembershipStatus.Invited;
                member.IsSubscribed = true;

                db.DiscussionGroupMembers.Add(member);
                db.SaveChanges();

                Emails.EnqueueEmail(
                        "*****@*****.**",
                        invitee.Email,
                        inviter.SecureFormattedName + " invited you to join " + group.Name,
                        Emails.FormatEmail(Didache.Resources.emails.discussiongroup_invitation, null, null, null, inviter, invitee, null, null, null, null, null, group),
                        false);

            }

            return Json(new { success = true} , JsonRequestBehavior.AllowGet);
        }