public static void ApproveClassmateRequest(int requesterUserID, int targetUserID)
        {
            DidacheDb db = new DidacheDb();

            UserRelationship rel1 = db.UserRelationships
                .SingleOrDefault(ur => ur.RequesterUserID == requesterUserID && ur.TargetUserID == targetUserID);

            UserRelationship rel2 = db.UserRelationships
                .SingleOrDefault(ur => ur.RequesterUserID == targetUserID && ur.TargetUserID == requesterUserID);

            if (rel1 != null) {
                rel1.Status = (int) RelationshipStatus.Approved;
            }
            if (rel2 != null) {
                rel2.Status = (int) RelationshipStatus.Approved;
            }

            //db.SaveChanges();

            // add user actions
            UserAction ua = new UserAction() {
                SourceUserID = requesterUserID,
                TargetUserID = targetUserID,
                UserActionType = UserActionType.BecomeClassmates,
                ActionDate = DateTime.Now,
                GroupID =0,
                MessageID = 0,
                PostCommentID = 0,
                PostID = 0,
                Text = ""
            };
            db.UserActions.Add(ua);
            UserAction ua2 = new UserAction() {
                SourceUserID = targetUserID,
                TargetUserID = requesterUserID,
                UserActionType = UserActionType.BecomeClassmates,
                ActionDate = DateTime.Now,
                GroupID = 0,
                MessageID = 0,
                PostCommentID = 0,
                PostID = 0,
                Text = ""
            };
            db.UserActions.Add(ua2);
            db.SaveChanges();
        }
Esempio n. 2
0
        public ActionResult AcceptDiscussionGroupInvite(int discussionGroupID)
        {
            var group = db.DiscussionGroups.Find(discussionGroupID);
            User user = Users.GetLoggedInUser();
            DiscussionGroupMember member = db.DiscussionGroupMembers.SingleOrDefault(gm => gm.UserID == user.UserID && gm.GroupID == discussionGroupID);

            if (member != null) {

                member.GroupMembershipStatus = GroupMembershipStatus.Member;
                member.IsSubscribed = true;

                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 });
        }
Esempio n. 3
0
        public ActionResult LeaveDiscussionGroup(int discussionGroupID)
        {
            var group = db.DiscussionGroups.Find(discussionGroupID);
            User user = Users.GetLoggedInUser();

            if (group != null && user != null) {
                DiscussionGroupMember member = db.DiscussionGroupMembers.SingleOrDefault(gm => gm.UserID == user.UserID && gm.GroupID == discussionGroupID);

                if (member != null) {
                    db.DiscussionGroupMembers.Remove(member);

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

                    db.SaveChanges();
                }
            }

            return Json(new { success = true });
        }
Esempio n. 4
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});
        }