예제 #1
0
        public DataTableResult <CustomNotification> SearchNotifications(DataTableAjaxPostModel model)
        {
            var searchBy = (model.search != null) ? model.search.value : null;
            var take     = model.length;
            var skip     = model.start;

            string sortBy  = "";
            bool   sortDir = true;

            if (model.order != null)
            {
                // in this example we just default sort on the 1st column
                sortBy  = model.columns[model.order[0].column].data;
                sortDir = model.order[0].dir.ToLower() == "asc";
            }

            // search the dbase taking into consideration table sorting and paging
            TittleNotificationServices           _Notificationservice = new TittleNotificationServices();
            DataTableResult <CustomNotification> result = new Models.DataTableResult <CustomNotification>();
            int filteredResultsCount = 0;
            int totalResultsCount    = 0;

            result.result = _Notificationservice.GetNotificationList(searchBy, take, skip, sortBy, sortDir, model.CustomData, out filteredResultsCount, out totalResultsCount);
            result.filteredResultsCount = filteredResultsCount;
            result.totalResultsCount    = totalResultsCount;
            if (result.result == null)
            {
                // empty collection...
                return(new DataTableResult <CustomNotification>());
            }
            return(result);
        }
예제 #2
0
        public ActionResult GetNotificationUsers(int Id)
        {
            TittleNotificationServices    notService = new TittleNotificationServices();
            List <CustomNotificationUser> model      = notService.GetNotificationUsersList(Id);

            return(PartialView("NotificationUser", model));
        }
예제 #3
0
 public ActionResult ReminderSetting()
 {
     if (Session["UserID"] != null)
     {
         TittleNotificationServices service = new TittleNotificationServices();
         system_settings            model   = service.GetSystemNotificationInfo();
         return(PartialView("ChangeReminderSetting", model));
     }
     return(null);
 }
예제 #4
0
        public ActionResult UpdateNotification(int Id)
        {
            TittleNotificationServices notificationService = new TittleNotificationServices();

            CustomNotification model = new CustomNotification();

            if (Id > 0)
            {
                notification notifcation = notificationService.GetNotificationInfo(Id);
                model.name    = notifcation.name;
                model.content = notifcation.content;
                model.OnDate  = Convert.ToDateTime(notifcation.time).ToString("dd/MM/yyyy hh:mm tt");
                if (notifcation.status.ToLower() == "draft")
                {
                    model.notificationStatus = NotificationStatus.Draft;
                }
                else
                {
                    model.notificationStatus = NotificationStatus.Published;
                }
                switch (notifcation.type.ToLower())
                {
                case "onetime":
                    model.notificationType = NotificationTypes.OneTime;
                    break;

                case "daily":
                    model.notificationType = NotificationTypes.Daily;
                    break;

                case "weekly":
                    model.notificationType = NotificationTypes.Weekly;
                    break;

                case "monthly":
                    model.notificationType = NotificationTypes.Monthly;
                    break;

                default:
                    model.notificationType = NotificationTypes.Daily;
                    break;
                }
            }
            else
            {
                model.notificationType   = NotificationTypes.Daily;
                model.notificationStatus = NotificationStatus.Draft;
            }

            return(PartialView("EditNotification", model));
        }
예제 #5
0
        public ActionResult DeleteNotification(int Id)
        {
            TittleNotificationServices notificationService = new TittleNotificationServices();
            string sMessage = "";

            if (Id > 0)
            {
                notificationService.DeleteNotification(Id, ref sMessage);
            }
            return(Json(new
            {
                message = sMessage
            }));
        }
예제 #6
0
        public ActionResult PublishNotification(int Id)
        {
            TittleNotificationServices notificationService = new TittleNotificationServices();
            string sMessage = "";

            if (Id > 0)
            {
                notification nt = notificationService.GetNotificationInfo(Id);
                nt.status = NotificationStatus.Published.ToString().ToLower();
                notificationService.UpdateNotificationInfo(nt);
            }
            return(Json(new
            {
                message = sMessage
            }));
        }
예제 #7
0
 public ActionResult ChangeNotificationSetting(string value)
 {
     if (Session["UserID"] != null)
     {
         TittleNotificationServices service = new TittleNotificationServices();
         service.UpdateSystemNotificationInfo(value);
         return(Json(new
         {
             message = "success"
         }, JsonRequestBehavior.AllowGet));
     }
     return(Json(new
     {
         message = "error"
     }, JsonRequestBehavior.AllowGet));
 }
예제 #8
0
        public ActionResult Index(CustomNotification model)
        {
            string sMessage = "";

            if (ModelState.IsValid)
            {
                TittleNotificationServices notificationService = new TittleNotificationServices();
                long nID = 0;
                model.status = model.notificationStatus.ToString().ToLower();
                model.type   = model.notificationType.ToString().ToLower();

                sMessage = notificationService.SaveOrUpdateNotification(model, ref nID);
            }

            return(Json(new
            {
                message = sMessage
            }));
        }
예제 #9
0
        public void Execute(IJobExecutionContext context)
        {
            PushNotification           fcm     = new PushNotification();
            TittleNotificationServices service = new TittleNotificationServices();
            //get all the active notifications
            List <notification> notifications = service.GetActiveNotifications();

            //loop through notifications
            if (notifications != null)
            {
                for (int i = 0; i < notifications.Count; i++)
                {
                    string message = notifications[i].content;
                    //get list of users in notification
                    List <CustomNotificationUser> users = service.GetNotificationUsersList(notifications[i].id);
                    if (users != null && users.Count > 0)
                    {
                        //loop through users
                        for (int j = 0; j < users.Count; j++)
                        {
                            //save in notification box
                            notification_boxes nb = new notification_boxes();
                            nb.type        = 10;
                            nb.device_id   = users[j].id;
                            nb.device_type = "App\\Models\\User";
                            nb.message     = message;
                            nb.task_id     = 0;
                            nb.unread      = "";
                            nb.seen        = 0;
                            nb.kid_id_ref  = 0;
                            service.SaveNotificationBoxInfo(nb);
                            //send notification one by one to devices
                            List <device> devices = service.GetListOfDevices(users[j].id);
                            for (int k = 0; k < devices.Count; k++)
                            {
                                fcm.Send(10, message, devices[k].id);
                            }
                        }
                    }
                    //update notification table
                    if (notifications[i].type == "onetime")
                    {
                        notifications[i].status = "completed";
                    }
                    else
                    {
                        if (notifications[i].type == "daily")
                        {
                            notifications[i].next_notification = ((DateTime)notifications[i].next_notification).AddDays(1);
                        }
                        else if (notifications[i].type == "weekly")
                        {
                            notifications[i].next_notification = ((DateTime)notifications[i].next_notification).AddDays(7);
                        }
                        else if (notifications[i].type == "monthly")
                        {
                            notifications[i].next_notification = ((DateTime)notifications[i].next_notification).AddMonths(1);
                        }
                    }
                    service.UpdateNotificationInfo(notifications[i]);
                }
            }
        }
예제 #10
0
        public ActionResult PushNotifications(CustomNotify model)
        {
            if (Session["UserID"] != null && ModelState.IsValid)
            {
                PushNotification           fcm      = new PushNotification();
                TittleUserServices         service  = new TittleUserServices();
                TittleNotificationServices nservice = new TittleNotificationServices();
                List <string> emails = null;

                if (model.Type == "immediately")
                {
                    if (!string.IsNullOrEmpty(model.To))
                    {
                        emails = model.To.Split('|').ToList();
                    }
                    else
                    {
                        emails = service.GetAllUsersEmail();
                    }
                    //loop through users and send notification
                    foreach (string email in emails)
                    {
                        List <CustomNotificationUser> users = nservice.GetUserDetailByEmail(email);
                        for (int j = 0; j < users.Count; j++)
                        {
                            //save in notification box
                            notification_boxes nb = new notification_boxes();
                            nb.type        = 10;
                            nb.device_id   = users[j].id;
                            nb.device_type = "App\\Models\\User";
                            nb.message     = model.Content;
                            nb.task_id     = 0;
                            nb.unread      = "";
                            nb.seen        = 0;
                            nb.kid_id_ref  = 0;
                            nservice.SaveNotificationBoxInfo(nb);
                            //send notification one by one to devices
                            List <device> devices = nservice.GetListOfDevices(users[j].id);
                            for (int k = 0; k < devices.Count; k++)
                            {
                                fcm.Send(10, model.Content, devices[k].id);
                            }
                        }
                    }
                }
                else
                {
                    CustomNotification not = new CustomNotification();
                    if (!string.IsNullOrEmpty(model.To))
                    {
                        not.data = "{\"users\":\"" + string.Join(",", model.To.Split('|')) + "\"}";
                    }
                    else
                    {
                        not.data = "{\"users\":\"all\"}";
                    }
                    not.content = model.Content;
                    not.name    = string.IsNullOrEmpty(model.Name)? "Unknown": model.Name;
                    not.OnDate  = model.TimeStart.HasValue ? model.TimeStart.Value.ToString("dd/MM/yyyy hh:mm tt") : null;
                    not.status  = model.Status;
                    not.type    = model.Type;
                    long nid = 0;
                    nservice.AddNotification(not, ref nid);
                }
                return(Json(new
                {
                    message = "success"
                }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new
            {
                message = "error"
            }, JsonRequestBehavior.AllowGet));
        }