/// <summary>
    /// Send notification to a specific userid
    /// </summary>
    /// <param name="iUserID"> the user id that needs to receive the notification</param>
    /// <param name="NotiType">the notification type</param>
    /// <param name="Message">The notification message</param>
    /// <param name="Link">the url of the link to go to</param>
    public void SendNotificationToUser(NotificationModel notification, int userID)
    {
        int notificationID = _NotificationService.Save(notification, userID);

        var objectToSend = new NotificationClientObject()
        {
            ID      = notificationID.ToString(),
            Time    = notification.CreateDate.ToString(),
            Link    = notification.Link,
            Message = notification.Message
        };


        if (ConnectionIds.ContainsKey(userID.ToString()))
        {
            foreach (var connectionID in ConnectionIds[userID.ToString()])
            {
                HubContext.Clients.Client(connectionID).receiveNotification(objectToSend);
            }
        }
    }
    /// <summary>
    /// Sends notification to multiple users
    /// </summary>
    /// <param name="iUserIDs">Array of the userids to receive the notification</param>
    /// <param name="NotiType"></param>
    /// <param name="Message"></param>
    /// <param name="Link"></param>
    public void SendNotificationToUser(NotificationModel notification, int[] userIDs)
    {
        int notificationID = _NotificationService.Save(notification, userIDs);

        var objectToSend = new NotificationClientObject()
        {
            ID      = notificationID.ToString(),
            Time    = DateTime.Now.ToString(),
            Link    = notification.Link,
            Message = notification.Message
        };

        List <string> recipientConnectionIDs = new List <string>();

        foreach (int userID in userIDs)
        {
            if (ConnectionIds.ContainsKey(userID.ToString()))
            {
                recipientConnectionIDs.AddRange(ConnectionIds[userID.ToString()]);
            }
        }

        HubContext.Clients.Clients(recipientConnectionIDs).receiveNotification(objectToSend);
    }
Example #3
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            profile        = (UserProfile)HttpContext.Session["_Profile"];
            controllerName = this.ControllerContext.HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();


            //-- for layout data----------//
            ViewBag.UserID   = profile.Id;
            ViewBag.UserName = GetSubStringUserName(profile.Name);
            ViewBag.CurTime  = UmAlQura.GetHijriDateFullString(DateTime.Now);
            //ViewBag.CurTime = QvLib.QVUtil.Date.GetHijriDate();
            ViewBag.LastVisit = profile.LastVisitTime;

            //-- for log method------------//
            var URL           = this.ControllerContext.HttpContext.Request.RawUrl;
            var isAngular     = this.ControllerContext.HttpContext.Request.Headers["FROM-ANGULAR"] == null ? false : true;
            var isNotLog      = (filterContext.ActionParameters.ContainsKey("bNotLog") && filterContext.ActionParameters["bNotLog"] != null) ? Convert.ToBoolean(filterContext.ActionParameters["bNotLog"]) : false;
            var IsChildAction = this.ControllerContext.IsChildAction ? this.ControllerContext.ParentActionViewContext.Controller.ControllerContext.HttpContext.Request.CurrentExecutionFilePath == this.ControllerContext.Controller.ControllerContext.HttpContext.Request.CurrentExecutionFilePath ? true : false : false;

            if (!filterContext.HttpContext.Request.IsAjaxRequest())
            {
                IEnumerable <PageModel> pages = new List <PageModel>();
                //  List<PageModel> pages = new List<PageModel>();

                var allPages = new CU_PageService().ParentPageList.Where(p => p.IsVisible && p.IsDeleted == false && (p.CU_Role_Page.Where(s => QvLib.Identity.Roles.Contains(s.IdRoleProgram)).Count() > 0 || p.CU_Page1.Any(g => g.CU_Role_Page.Where(s => QvLib.Identity.Roles.Contains(s.IdRoleProgram)).Count() > 0)));
                pages = new CU_PageService().ParentPageList.Where(p => p.IsVisible && p.IsDeleted == false && p.ParentID == null && (p.CU_Role_Page.Where(s => QvLib.Identity.Roles.Contains(s.IdRoleProgram)).Count() > 0 || p.CU_Page1.Any(g => g.CU_Role_Page.Where(s => QvLib.Identity.Roles.Contains(s.IdRoleProgram)).Count() > 0)));

                var pagesPermissions = _ActionService.GetPermission(allPages.Select(a => a.URL.ToLower()).ToList(), profile.Id.Value);

                foreach (var i in pages)
                {
                    List <PageModel> childPages = new List <PageModel>();

                    // var parentPagePermission = _ActionService.GetPermission(i.URL, profile.Id.Value);
                    var parentPagePermission = pagesPermissions[i.URL.ToLower()];
                    if (parentPagePermission.ContainsValue(true))
                    {
                        i.HasPermission = true;
                    }


                    var allChildPages = i.CU_Page1.Where(p => p.CU_Role_Page.Where(s => p.IsVisible && p.IsDeleted == false && QvLib.Identity.Roles.Contains(s.IdRoleProgram)).Count() > 0).ToList();
                    if (allChildPages.Count != 0)
                    {
                        foreach (var item in allChildPages)
                        {
                            //var childPagePermission = _ActionService.GetPermission(item.URL, profile.Id.Value);
                            var childPagePermission = pagesPermissions[item.URL.ToLower()];
                            if (childPagePermission.ContainsValue(true))
                            {
                                item.HasPermission = true;
                                childPages.Add(item);
                            }
                        }
                        if (childPages.Count != 0)
                        {
                            i.CU_Page1      = childPages;
                            i.HasPermission = true;
                        }

                        else
                        {
                            i.CU_Page1 = new List <PageModel>();
                        }
                    }
                }


                ViewBag.Pages       = pages;
                ViewBag.ParentPages = pages;

                //----------------------------//
                // ViewBag.UserType = profile.UserType;
                // ViewBag.Currency = new SettingService().GetCurrency();
                // ViewBag.CountryID = new SettingService().GetDefaultCountryID();
                ViewBag.CurrentPage = new CU_PageService().GetPageModelByPageURL(controllerName);
                //------------------------Notifications--------------------------------------------------//
                var unseenNotificationsModelList = new NotificationService().GetUnseenNotifications(profile.Id.Value).OrderByDescending(a => a.CreateDate);

                var clientNotificationsList = new List <NotificationClientObject>();

                foreach (NotificationModel not in unseenNotificationsModelList)
                {
                    NotificationClientObject notification = new NotificationClientObject();

                    notification.Message = not.Message;
                    notification.ID      = not.ID.ToString();
                    notification.Time    = not.CreateDate.ToString();
                    notification.Link    = not.Link;
                    clientNotificationsList.Add(notification);
                }

                ViewBag.UnSeenNotifications = clientNotificationsList;
                //--------------------------------------------------------------//
            }
        }