示例#1
0
        /*
         * ///<summary></summary>
         * public static void Update(TaskSubscription subsc) {
         *      if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
         *              Meth.GetVoid(MethodBase.GetCurrentMethod(),subsc);
         *              return;
         *      }
         *      Crud.TaskSubscriptionCrud.Update(subsc);
         * }*/

        ///<summary>Attempts to create a subscription to a TaskList with TaskListNum of subscribeToTaskListNum.
        ///The curUserNum must be the currently logged in user.</summary>
        public static bool TrySubscList(long subscribeToTaskListNum, long curUserNum)
        {
            //No remoting role check; no call to db
            //Get the list of directly subscribed TaskListNums.  This avoids the concurrency issue of the same user logged in via multiple WS and
            //subscribing to the same TaskList.  Additionally, this allows the user to directly subscribe to child TaskLists of subscribed parent Tasklists
            //which was old behavior that was inadvertently removed.
            List <long> listExistingSubscriptionNums = GetTaskSubscriptionsForUser(curUserNum).Select(x => x.TaskListNum).ToList();

            if (listExistingSubscriptionNums.Contains(subscribeToTaskListNum))
            {
                return(false);               //Already subscribed.
            }
            //Get all currently subscribed unread Reminder tasks before adding new subscription.
            List <long>      listReminderTaskNumsOld = GetUnreadReminderTasks(curUserNum).Select(x => x.TaskNum).ToList();
            TaskSubscription subsc = new TaskSubscription();

            subsc.IsNew       = true;
            subsc.UserNum     = curUserNum;
            subsc.TaskListNum = subscribeToTaskListNum;
            Insert(subsc);
            //Get newly subscribed unread Reminder tasks.
            List <Task> listNewReminderTasks = GetUnreadReminderTasks(curUserNum).FindAll(x => !x.TaskNum.In(listReminderTaskNumsOld));

            //Set any past unread Reminder tasks as read.
            TaskUnreads.SetRead(curUserNum, listNewReminderTasks.FindAll(x => x.DateTimeEntry < DateTime.Now).ToArray());
            //Get all future reminders in the newly subscribed Tasklist (and sub Tasklists) that the user was not previously subscribed to.
            List <Task> listFutureReminders = GetNewReadReminders(listExistingSubscriptionNums, subscribeToTaskListNum, curUserNum)
                                              .Where(x => x.DateTimeEntry >= DateTime.Now).ToList();

            //We already know these tasks do not have any TaskUnreads (due to GetNewReadReminders->Tasks.RefreshChildren()), safe to insert TaskUnreads.
            TaskUnreads.InsertManyForTasks(listFutureReminders, curUserNum);
            return(true);
        }
示例#2
0
        ///<summary>Removes a subscription to a list.</summary>
        public static void UnsubscList(long taskListNum, long userNum)
        {
            if (RemotingClient.RemotingRole == RemotingRole.ClientWeb)
            {
                Meth.GetVoid(MethodBase.GetCurrentMethod(), taskListNum, userNum);
                return;
            }
            //Get all future unread reminders
            List <Task> listFutureUnreadReminders = Tasks.GetNewTasksThisUser(userNum, 0)        //Use clinicnum=0 to get all tasks, no task clinic filtering.
                                                    .Where(x => Tasks.IsReminderTask(x) && x.DateTimeEntry >= DateTime.Now)
                                                    .ToList();
            string command = "DELETE FROM tasksubscription "
                             + "WHERE UserNum=" + POut.Long(userNum)
                             + " AND TaskListNum=" + POut.Long(taskListNum);

            Db.NonQ(command);
            List <Task> listStillSubscribed = Tasks.GetNewTasksThisUser(userNum, 0)        //Use clinicnum=0 to get all tasks, no task clinic filtering.
                                              .Where(x => Tasks.IsReminderTask(x) && x.DateTimeEntry >= DateTime.Now).ToList();
            List <Task> listUnSubTasksForUser = listFutureUnreadReminders.Where(x => !x.TaskNum.In(listStillSubscribed.Select(y => y.TaskNum))).ToList();

            //Set unsubbed reminders in the future to be read so reminders wont show in NewForUser tasklist.
            TaskUnreads.SetRead(userNum, listUnSubTasksForUser.ToArray());
        }