public HttpResponseMessage FollowBack(NotificationDTO postData)
        {
            var success = false;

            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
                if (recipient != null)
                {
                    var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                    int targetUserId;
                    if (int.TryParse(notification.Context, out targetUserId))
                    {
                        var targetUser = UserController.GetUserById(PortalSettings.PortalId, targetUserId);

                        FollowersController.Instance.FollowUser(targetUser);
                        NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);

                        success = true;
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }

            if (success)
            {
                return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
            }

            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
        }
예제 #2
0
        public HttpResponseMessage FollowBack(NotificationDTO postData)
        {
            var success = false;

            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
                if (recipient != null)
                {
                    var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                    int targetUserId;
                    if (int.TryParse(notification.Context, out targetUserId))
                    {
                        var targetUser = UserController.GetUserById(PortalSettings.PortalId, targetUserId);

                        FollowersController.Instance.FollowUser(targetUser);
                        NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);

                        success = true;
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }

            if (success)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
예제 #3
0
        public HttpResponseMessage Approve(NotificationDTO postData)
        {
            try
            {
                var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                if (notification != null)
                {
                    if (string.IsNullOrEmpty(notification.Context))
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                    }

                    string[] parameters = notification.Context.Split(':');

                    var stateTransiction = new StateTransaction
                    {
                        ContentItemId  = int.Parse(parameters[0]),
                        CurrentStateId = int.Parse(parameters[2]),
                        Message        = new StateTransactionMessage(),
                        UserId         = UserInfo.UserID
                    };
                    _workflowEngine.CompleteState(stateTransiction);

                    return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
        public HttpResponseMessage AcceptFriend(NotificationDTO postData)
        {
            var success = false;

            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
                if (recipient != null)
                {
                    var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                    int userRelationshipId;
                    if (int.TryParse(notification.Context, out userRelationshipId))
                    {
                        var userRelationship = RelationshipController.Instance.GetUserRelationship(userRelationshipId);
                        if (userRelationship != null)
                        {
                            var friend = UserController.GetUserById(PortalSettings.PortalId, userRelationship.UserId);
                            FriendsController.Instance.AcceptFriend(friend);
                            success = true;
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }
            
            if(success)
            {
                return Request.CreateResponse(HttpStatusCode.OK, new {Result = "success"});
            }

            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
        }
예제 #5
0
        public HttpResponseMessage AcceptFriend(NotificationDTO postData)
        {
            var success = false;

            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, this.UserInfo.UserID);
                if (recipient != null)
                {
                    var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                    int userRelationshipId;
                    if (int.TryParse(notification.Context, out userRelationshipId))
                    {
                        var userRelationship = RelationshipController.Instance.GetUserRelationship(userRelationshipId);
                        if (userRelationship != null)
                        {
                            var friend = UserController.GetUserById(this.PortalSettings.PortalId, userRelationship.UserId);
                            FriendsController.Instance.AcceptFriend(friend);
                            success = true;
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }

            if (success)
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
            }

            return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
        public HttpResponseMessage Reject(NotificationDTO postData)
        {
            try
            {
                var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                if (notification != null)
                {
                    if (string.IsNullOrEmpty(notification.Context))
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
                    }

                    string[] parameters = notification.Context.Split(':');

                    var stateTransiction = new StateTransaction
                                           {
                                               ContentItemId = int.Parse(parameters[0]),
                                               CurrentStateId = int.Parse(parameters[2]),
                                               Message = new StateTransactionMessage (),
                                               UserId = UserInfo.UserID
                                           };
                    _workflowEngine.DiscardState(stateTransiction);

                    return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
                }
            }
            catch (Exception exc)
            {
                Exceptions.LogException(exc);
            }

            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");
        }
예제 #7
0
        public HttpResponseMessage FollowBack(NotificationDTO postData)
        {
            var success = false;

            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, this.UserInfo.UserID);
                if (recipient != null)
                {
                    var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);
                    int targetUserId;
                    if (int.TryParse(notification.Context, out targetUserId))
                    {
                        var targetUser = UserController.GetUserById(this.PortalSettings.PortalId, targetUserId);

                        if (targetUser == null)
                        {
                            var response = new
                            {
                                Message = Localization.GetExceptionMessage(
                                    "UserDoesNotExist",
                                    "The user you are trying to follow no longer exists."),
                            };
                            return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, response));
                        }

                        FollowersController.Instance.FollowUser(targetUser);
                        NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, this.UserInfo.UserID);

                        success = true;
                    }
                }
            }
            catch (UserRelationshipExistsException exc)
            {
                Logger.Error(exc);
                var response = new
                {
                    Message = Localization.GetExceptionMessage(
                        "AlreadyFollowingUser",
                        "You are already following this user."),
                };
                return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc.Message));
            }

            if (success)
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
            }

            return(this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
        private UserInfo GetUser(NotificationDTO notificationDto)
        {
            var notification = NotificationsController.Instance.GetNotification(notificationDto.NotificationId);

            int userId;
            if (!int.TryParse(notification.Context, out userId))
            {
                return null;
            }

            return UserController.GetUserById(PortalSettings.PortalId, userId);            
        }
예제 #9
0
        private UserInfo GetUser(NotificationDTO notificationDto)
        {
            var notification = NotificationsController.Instance.GetNotification(notificationDto.NotificationId);

            int userId;

            if (!int.TryParse(notification.Context, out userId))
            {
                return(null);
            }

            return(UserController.GetUserById(PortalSettings.PortalId, userId));
        }
        public HttpResponseMessage Reject(NotificationDTO postData)
        {
            var user = GetUser(postData);
            if (user == null)
            {
                NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found");
            }

            UserController.RemoveUser(user);

            return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
        }
        public HttpResponseMessage Authorize(NotificationDTO postData)
        {
            var user = GetUser(postData);
            if (user == null)
            {
                NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found");
            }

            user.Membership.Approved = true;
            UserController.UpdateUser(PortalSettings.PortalId, user);
            
            return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
        }
예제 #12
0
        public HttpResponseMessage Reject(NotificationDTO postData)
        {
            var user = GetUser(postData);

            if (user == null)
            {
                NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found"));
            }

            UserController.RemoveUser(user);

            return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
        }
        public HttpResponseMessage Review(NotificationDTO postData)
        {
            try
            {
                var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);

                if (notification != null)
                {
                    //Dismiss the notification
                    NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);

                    if (string.IsNullOrEmpty(notification.Context))
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success"});
                    }

                    var source = notification.Context;
                    string[] parameters = null;
                    if (notification.Context.Contains(";"))
                    {
                        parameters = notification.Context.Split(';');
                        source = parameters[0];
                        parameters = parameters.ToList().Skip(1).ToArray();
                    }

                    var workflow = ContentWorkflowController.Instance.GetDefaultWorkflow(PortalSettings.PortalId);
                    var workflowSource = ContentWorkflowController.Instance.GetWorkflowSource(workflow.WorkflowID, source);
                    if (workflowSource == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
                    }

                    var sourceAction = Reflection.CreateInstance(Reflection.CreateType(workflowSource.SourceType)) as IContentWorkflowAction;
                    if (sourceAction == null)
                    {
                        return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" });
                    }

                    return Request.CreateResponse(HttpStatusCode.OK, new { Result = "success", Link = sourceAction.GetAction(parameters) }); 
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }

            return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification");

        }
        public HttpResponseMessage Authorize(NotificationDTO postData)
        {
            var user = GetUser(postData);

            if (user == null)
            {
                NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found"));
            }

            user.Membership.Approved = true;
            UserController.UpdateUser(PortalSettings.PortalId, user);

            return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
        }
        public HttpResponseMessage Review(NotificationDTO postData)
        {
            try
            {
                var notification = NotificationsController.Instance.GetNotification(postData.NotificationId);

                if (notification != null)
                {
                    //Dismiss the notification
                    NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);

                    if (string.IsNullOrEmpty(notification.Context))
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                    }

                    var      source     = notification.Context;
                    string[] parameters = null;
                    if (notification.Context.Contains(";"))
                    {
                        parameters = notification.Context.Split(';');
                        source     = parameters[0];
                        parameters = parameters.ToList().Skip(1).ToArray();
                    }

                    var workflow       = ContentWorkflowController.Instance.GetDefaultWorkflow(PortalSettings.PortalId);
                    var workflowSource = ContentWorkflowController.Instance.GetWorkflowSource(workflow.WorkflowID, source);
                    if (workflowSource == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                    }

                    var sourceAction = Reflection.CreateInstance(Reflection.CreateType(workflowSource.SourceType)) as IContentWorkflowAction;
                    if (sourceAction == null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                    }

                    return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success", Link = sourceAction.GetAction(parameters) }));
                }
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
            }

            return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "unable to process notification"));
        }
예제 #16
0
        public HttpResponseMessage Dismiss(NotificationDTO postData)
        {
            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
                if (recipient != null)
                {
                    NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);
                    return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
                }

                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unable to dismiss notification"));
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc));
            }
        }
        public HttpResponseMessage Dismiss(NotificationDTO postData)
        {
            try
            {
                var recipient = InternalMessagingController.Instance.GetMessageRecipient(postData.NotificationId, UserInfo.UserID);
                if (recipient != null)
                {
                    NotificationsController.Instance.DeleteNotificationRecipient(postData.NotificationId, UserInfo.UserID);
                    return Request.CreateResponse(HttpStatusCode.OK, new {Result = "success"});
                }

                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unable to dismiss notification");
            }
            catch (Exception exc)
            {
                Logger.Error(exc);
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc);
            }
        }
예제 #18
0
        public HttpResponseMessage Authorize(NotificationDTO postData)
        {
            var user = GetUser(postData);

            if (user == null)
            {
                NotificationsController.Instance.DeleteNotification(postData.NotificationId);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "User not found"));
            }

            user.Membership.Approved = true;
            UserController.UpdateUser(PortalSettings.PortalId, user);

            //Update User Roles if needed
            if (!user.IsSuperUser && user.IsInRole("Unverified Users") && PortalSettings.UserRegistration == (int)Globals.PortalRegistrationType.VerifiedRegistration)
            {
                UserController.ApproveUser(user);
            }

            Mail.SendMail(user, MessageType.UserAuthorized, PortalSettings);

            return(Request.CreateResponse(HttpStatusCode.OK, new { Result = "success" }));
        }
예제 #19
0
        public HttpResponseMessage SendVerificationMail(NotificationDTO postData)
        {
            if (UserInfo.Membership.Approved)
            {
                throw new UserAlreadyVerifiedException();
            }

            if (!UserInfo.IsInRole("Unverified Users"))
            {
                throw new InvalidVerificationCodeException();
            }

            var message = Mail.SendMail(UserInfo, MessageType.UserRegistrationVerified, PortalSettings);

            if (string.IsNullOrEmpty(message))
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new { Result = Localization.GetSafeJSString("VerificationMailSendSuccessful", Localization.SharedResourceFile) }));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, message));
            }
        }