Example #1
0
        public HttpResponseMessage MarkAsRead(Guid notificationId)
        {
            try
            {
                var currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();

                if (!currentUser.IsInRole("Registered Users"))
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Unauthorized));
                }

                NotificationComponent notificationComponent = new NotificationComponent(notificationId);
                if (notificationComponent.Notification.UserId == currentUser.UserID)
                {
                    notificationComponent.Notification.Read = DateTime.Now;
                    if (notificationComponent.Save() > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Successful Operation"));
                    }
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
                }
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (HttpResponseException e)
            {
                throw e;
            }
            catch (Exception ee)
            {
                DotNetNuke.Services.Exceptions.Exceptions.LogException(ee);
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
            }
        }
Example #2
0
        public static int SetNotification(string indicatorType, string objectType, Guid objectId, int toUserId, int?fromUserId, string tag)
        {
            NotificationComponent notificationComponent = new NotificationComponent();

            notificationComponent.Notification.Code       = indicatorType;
            notificationComponent.Notification.Created    = DateTime.Now;
            notificationComponent.Notification.UserId     = toUserId;
            notificationComponent.Notification.Message    = "V1";
            notificationComponent.Notification.ToolTip    = "V1";
            notificationComponent.Notification.Link       = objectId.ToString();
            notificationComponent.Notification.ObjectType = objectType;
            notificationComponent.Notification.Tag        = tag;

            if (fromUserId.HasValue == true)
            {
                notificationComponent.Notification.UserNotificationConnections.Add(new UserNotificationConnection()
                {
                    UserNotificationConnection1 = Guid.NewGuid(),
                    UserId = fromUserId.Value,
                    Rol    = string.Empty
                });
            }
            return(notificationComponent.Save());
        }