示例#1
0
        public static void CompleteTask(int id, string host, CMSDataContext db)
        {
            var gcm      = new GCMHelper(host, db);
            var task     = db.Tasks.Single(t => t.Id == id);
            var sb       = new StringBuilder();
            var statusId = TaskStatusCode.Complete;

            ChangeTask(sb, task, "StatusId", statusId, host, db);
            NotifyIfNeeded(sb, task, host, db);
            db.SubmitChanges();

            if (task.Owner.PeopleId == Util.UserPeopleId)
            {
                if (task.CoOwner != null)
                {
                    gcm.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task they delegated to you");
                }
            }
            else
            {
                gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task you delegated them");
            }

            if (Util.UserPeopleId.HasValue)
            {
                gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
            }
        }
示例#2
0
        public static void Delegate(int taskId, int toId, string host, CMSDataContext db, bool notify = true, bool forceCompleteWithContact = false)
        {
            if (toId == Util.UserPeopleId)
            {
                return; // cannot delegate to self
            }

            var gcm = new GCMHelper(host, db);

            var task = db.Tasks.SingleOrDefault(t => t.Id == taskId);

            if (task == null)
            {
                return;
            }

            var previousDelegatee = task.CoOwnerId ?? 0;

            task.StatusId  = TaskStatusCode.Pending;
            task.CoOwnerId = toId;

            if (forceCompleteWithContact)
            {
                task.ForceCompleteWContact = true;
            }

            var toPerson = db.LoadPersonById(toId);

            db.SubmitChanges();
            db.Email(task.Owner.EmailAddress, toPerson, $"Task delegated to you by {Util.UserFullName}", CreateEmailBody(task, host, db));

            if (!notify)
            {
                return;
            }

            if (previousDelegatee == 0) // No previous delegatee
            {
                gcm.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskId, "Task Delegated", $"{Util.UserFullName} delegated you a task");
                gcm.sendRefresh(task.Owner.PeopleId, GCMHelper.TYPE_TASK);
            }
            else // Had a previous delegatee
            {
                if (previousDelegatee == Util.UserPeopleId) // Delegatee redelegating
                {
                    gcm.sendRefresh(previousDelegatee, GCMHelper.TYPE_TASK);
                    gcm.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskId, "Task Delegated", $"{Util.UserFullName} has delegated a task to you");
                    gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, taskId, "Task Redelegated", $"{Util.UserFullName} has redelegated a task you delegated to them");
                }
                else // Owner, with previous delegatee
                {
                    gcm.sendRefresh(task.Owner.PeopleId, GCMHelper.TYPE_TASK);
                    gcm.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskId, "Task Delegated", $"{Util.UserFullName} delegated you a task");
                    gcm.sendNotification(previousDelegatee, GCMHelper.TYPE_TASK, 0, "Task Redelegated", $"{Util.UserFullName} has redelegated a task to someone else");
                }
            }
        }
示例#3
0
        public void ChangeOwner(int taskid, int toid)
        {
            if (toid == Util.UserPeopleId.Value)
            {
                return; // nothing to do
            }
            var task = DbUtil.Db.Tasks.Single(t => t.Id == taskid);

            // if the owner's list is shared by the coowner
            // then put it in owner's list
            // otherwise put it in the coowner's inbox
            var owner   = task.Owner;
            var toowner = DbUtil.Db.LoadPersonById(toid);

            //if (task.TaskList.TaskListOwners.Any(tlo => tlo.PeopleId == toid) || task.TaskList.CreatedBy == toid)
            //    task.CoListId = task.ListId;
            //else
            //    task.ListId = InBoxId(toid);

            //task.CoOwnerId = task.OwnerId;
            task.OrginatorId = task.OwnerId;
            task.Owner       = toowner;

            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Email(owner.EmailAddress, toowner, $"Task transferred to you from {owner.Name}", CreateEmailBody(task));

            GCMHelper.sendNotification(toid, GCMHelper.TYPE_TASK, task.Id, "Task Transferred", $"{Util.UserFullName} has transferred a task to you");
            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);

            if (task.CoOwner != null)
            {
                GCMHelper.sendRefresh(task.CoOwner.PeopleId, GCMHelper.ACTION_REFRESH);
            }
        }
示例#4
0
        public void DelegateAll(IEnumerable <int> tasks, int peopleID)
        {
            var owners = (from o in DbUtil.Db.Tasks
                          where tasks.Contains(o.Id)
                          select o.OwnerId).Distinct().ToList();

            var delegates = (from o in DbUtil.Db.Tasks
                             where tasks.Contains(o.Id)
                             where o.CoOwnerId != null
                             select o.CoOwnerId ?? 0).Distinct().ToList();

            foreach (var tid in tasks)
            {
                Delegate(tid, peopleID, false, true);
            }

            owners.Remove(Util.UserPeopleId.Value);
            owners.Remove(peopleID);
            delegates.Remove(Util.UserPeopleId.Value);
            delegates.Remove(peopleID);

            string taskString = tasks.Count() > 1 ? "tasks" : "a task";

            GCMHelper.sendNotification(owners, GCMHelper.TYPE_TASK, 0, "Tasks Redelegated", $"{Util.UserFullName} has redelegated {taskString} you own");
            GCMHelper.sendNotification(delegates, GCMHelper.TYPE_TASK, 0, "Tasks Redelegated", $"{Util.UserFullName} has redelegated {taskString} to someone else");
            GCMHelper.sendNotification(peopleID, GCMHelper.TYPE_TASK, 0, "Task Delegated", $"{Util.UserFullName} delegated you {taskString}");
            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);

            DbUtil.Db.SubmitChanges();
        }
示例#5
0
        public static bool DeclineTask(User user, int id, string reason, string host, CMSDataContext db)
        {
            var gcm  = new GCMHelper(host, db);
            var task = db.Tasks.SingleOrDefault(t => t.Id == id);

            if (task == null)
            {
                return(false);
            }

            task.StatusId      = TaskStatusCode.Declined;
            task.DeclineReason = reason;

            db.SubmitChanges();
            db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task declined by {user.Person.Name}", CreateEmailBody(task, host, db));

            gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Declined", $"{user.Person.Name} declined a task");

            if (user.PeopleId.HasValue)
            {
                gcm.sendRefresh(user.PeopleId.Value, GCMHelper.TYPE_TASK);
            }

            return(true);
        }
示例#6
0
        public void DeleteTasks(IEnumerable <int> list)
        {
            var owners = (from o in DbUtil.Db.Tasks
                          where list.Contains(o.Id)
                          select o.OwnerId).Distinct().ToList();

            var delegates = (from o in DbUtil.Db.Tasks
                             where list.Contains(o.Id)
                             where o.CoOwnerId != null
                             select o.CoOwnerId ?? 0).Distinct().ToList();

            foreach (var id in list)
            {
                DeleteTask(id, false);
            }

            owners.Remove(Util.UserPeopleId.Value);
            delegates.Remove(Util.UserPeopleId.Value);

            string taskString = list.Count() > 1 ? "tasks" : "a task";

            GCMHelper.sendNotification(owners, GCMHelper.TYPE_TASK, 0, "Tasks Deleted", $"{Util.UserFullName} has deleted {taskString} you owned");
            GCMHelper.sendNotification(delegates, GCMHelper.TYPE_TASK, 0, "Tasks Deleted", $"{Util.UserFullName} has deleted {taskString} delegated to you");
            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
        }
示例#7
0
        public static void ChangeOwner(int taskId, int toId, string host, CMSDataContext db)
        {
            var gcm = new GCMHelper(host, db);

            if (toId == Util.UserPeopleId)
            {
                return; // nothing to do
            }

            var task = db.Tasks.Single(t => t.Id == taskId);

            var owner   = task.Owner;
            var toOwner = db.LoadPersonById(toId);

            //task.CoOwnerId = task.OwnerId;
            task.OrginatorId = task.OwnerId;
            task.Owner       = toOwner;

            db.SubmitChanges();
            db.Email(owner.EmailAddress, toOwner, $"Task transferred to you from {owner.Name}", CreateEmailBody(task, host, db));

            gcm.sendNotification(toId, GCMHelper.TYPE_TASK, task.Id, "Task Transferred", $"{Util.UserFullName} has transferred a task to you");

            if (Util.UserPeopleId.HasValue)
            {
                gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
            }

            if (task.CoOwner != null)
            {
                gcm.sendRefresh(task.CoOwner.PeopleId, GCMHelper.ACTION_REFRESH);
            }
        }
示例#8
0
        public void UpdateTask()
        {
            var gcm  = new GCMHelper(_host, _cmsDataContext);
            var sb   = new StringBuilder();
            var task = _cmsDataContext.Tasks.Single(t => t.Id == Id);

            ChangeTask(sb, task, "Description", Description, _host, _cmsDataContext);
            ChangeTask(sb, task, "LimitToRole", TaskLimitToRole.Value == "0" ? null : TaskLimitToRole.Value, _host, _cmsDataContext);
            ChangeTask(sb, task, "Due", Due, _host, _cmsDataContext);
            ChangeTask(sb, task, "Notes", Notes, _host, _cmsDataContext);
            ChangeTask(sb, task, "StatusId", TaskStatus.IntVal, _host, _cmsDataContext);
            task.ForceCompleteWContact = ForceCompleteWithContact;

            if (HttpContext.Current.User.IsInRole("AdvancedTask"))
            {
                ChangeTask(sb, task, "Project", Project, _host, _cmsDataContext);
            }

            task.Location = Location;

            task.Priority = Priority == 0 ? null : Priority;

            _cmsDataContext.SubmitChanges();
            NotifyIfNeeded(sb, task, _host, _cmsDataContext);

            if (task.Owner.PeopleId == Util.UserPeopleId)
            {
                if (task.CoOwner != null)
                {
                    gcm.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Updated", $"{Util.UserFullName} updated a task delegated to you");
                }
            }
            else
            {
                gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Updated", $"{Util.UserFullName} updated a task you own");
            }

            if (Util.UserPeopleId.HasValue)
            {
                gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
            }
        }
示例#9
0
        public void AcceptTask(int id)
        {
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == id);

            task.StatusId = TaskStatusCode.Active;
            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task accepted by {Util.UserFullName}", CreateEmailBody(task));

            GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Accepted", $"{Util.UserFullName} accepted a task");
            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
        }
示例#10
0
        public int AddCompletedContact(int id)
        {
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == id);
            var c    = new Contact {
                ContactDate = Util.Now.Date
            };

            c.CreatedDate = c.ContactDate;
            var min = DbUtil.Db.Ministries.SingleOrDefault(m => m.MinistryName == task.Project);

            if (min != null)
            {
                c.MinistryId = min.MinistryId;
            }
            c.contactees.Add(new Contactee {
                PeopleId = task.WhoId.Value
            });
            c.contactsMakers.Add(new Contactor {
                PeopleId = PeopleId
            });
            c.Comments            = task.Notes;
            task.CompletedContact = c;
            task.StatusId         = TaskStatusCode.Complete;

            if (task.CoOwnerId == PeopleId)
            {
                DbUtil.Db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task completed with a Contact by {Util.UserFullName}", CreateEmailBody(task));
            }
            else if (task.CoOwnerId != null)
            {
                DbUtil.Db.Email(task.Owner.EmailAddress, task.CoOwner, $"Task completed with a Contact by {Util.UserFullName}", CreateEmailBody(task));
            }

            task.CompletedOn = c.ContactDate;

            DbUtil.Db.SubmitChanges();

            if (task.Owner.PeopleId == Util.UserPeopleId)
            {
                if (task.CoOwner != null)
                {
                    GCMHelper.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task they delegated to you");
                }
            }
            else
            {
                GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task you delegated them");
            }

            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);

            return(c.ContactId);
        }
示例#11
0
        public void DeclineTask(int id, string reason)
        {
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == id);

            task.StatusId      = TaskStatusCode.Declined;
            task.DeclineReason = reason;

            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task declined by {Util.UserFullName}", CreateEmailBody(task));

            GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Declined", $"{Util.UserFullName} declined a task");
            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
        }
示例#12
0
        public static void SetWhoId(int id, int pid)
        {
            var task = DbUtil.Db.Tasks.Single(t => t.Id == id);

            task.WhoId = pid;
            DbUtil.Db.SubmitChanges();

            if (task.CoOwner != null)
            {
                GCMHelper.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Tasks About Changed", $"{Util.UserFullName} has change the about person on a task delegated to you");
            }

            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
        }
示例#13
0
        public static bool CompleteTask(User user, int id, string host, CMSDataContext db)
        {
            var gcm  = new GCMHelper(host, db);
            var task = db.Tasks.SingleOrDefault(t => t.Id == id);

            if (task == null)
            {
                return(false);
            }

            var sb = new StringBuilder();

            ChangeTask(sb, task, "StatusId", TaskStatusCode.Complete, host, db);

            NotifyIfNeeded(user, task, sb, host, db);

            db.SubmitChanges();

            if (task.Owner.PeopleId == user.PeopleId)
            {
                if (task.CoOwner != null)
                {
                    gcm.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{user.Person.Name} completed a task they delegated to you");
                }
            }
            else
            {
                gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{user.Person.Name} completed a task you delegated them");
            }

            if (user.PeopleId.HasValue)
            {
                gcm.sendRefresh(user.PeopleId.Value, GCMHelper.TYPE_TASK);
            }

            return(true);
        }
示例#14
0
        internal void Delegate(int toPeopleId)
        {
            var owners = (from o in _dataContext.Tasks
                          where SelectedItem.Contains(o.Id)
                          select o.OwnerId).Distinct().ToList();

            var delegates = (from o in _dataContext.Tasks
                             where SelectedItem.Contains(o.Id)
                             where o.CoOwnerId != null
                             select o.CoOwnerId ?? 0).Distinct().ToList();

            foreach (var tid in SelectedItem)
            {
                TaskModel.Delegate(tid, toPeopleId, _host, _dataContext, true, true);
            }

            if (Util.UserPeopleId.HasValue)
            {
                owners.Remove(Util.UserPeopleId.Value);
                delegates.Remove(Util.UserPeopleId.Value);
            }
            owners.Remove(toPeopleId);
            delegates.Remove(toPeopleId);

            string taskString = SelectedItem.Count() > 1 ? "tasks" : "a task";

            _gcm.sendNotification(owners, GCMHelper.TYPE_TASK, 0, "Tasks Redelegated", $"{Util.UserFullName} has redelegated {taskString} you own");
            _gcm.sendNotification(delegates, GCMHelper.TYPE_TASK, 0, "Tasks Redelegated", $"{Util.UserFullName} has redelegated {taskString} to someone else");
            _gcm.sendNotification(toPeopleId, GCMHelper.TYPE_TASK, 0, "Task Delegated", $"{Util.UserFullName} delegated you {taskString}");

            if (Util.UserPeopleId.HasValue)
            {
                _gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
            }

            _dataContext.SubmitChanges();
        }
示例#15
0
        public void DeleteTask(int TaskId, bool notify = true)
        {
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == TaskId);

            if (task == null)
            {
                return;
            }
            if (task.OwnerId == PeopleId)
            {
                if (task.CoOwnerId != null)
                {
                    DbUtil.Db.Email(task.Owner.EmailAddress, task.CoOwner, $"Task deleted by {Util.UserFullName}", CreateEmailBody(task));
                }

                DbUtil.Db.Tasks.DeleteOnSubmit(task);
                DbUtil.Db.SubmitChanges();
            }
            else if (HttpContext.Current.User.IsInRole("Admin"))
            {
                DbUtil.Db.Tasks.DeleteOnSubmit(task);
                DbUtil.Db.SubmitChanges();
            }
            else // I must be cowner, I can't delete
            {
                DbUtil.Db.Email(task.CoOwner.EmailAddress, task.Owner, $"{Util.UserFullName} tried to delete task", CreateEmailBody(task));
            }

            if (notify)
            {
                if (task.Owner.PeopleId == Util.UserPeopleId.Value)
                {
                    if (task.CoOwner != null)
                    {
                        GCMHelper.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, 0, "Task Deleted", $"{Util.UserFullName} has deleted a task delegated to you");
                    }
                }
                else
                {
                    GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, 0, "Task Deleted", $"{Util.UserFullName} has deleted a task you owned");
                }

                GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
            }
        }
示例#16
0
        public static void SetWhoId(int id, int pid, string host, CMSDataContext db)
        {
            var gcm  = new GCMHelper(host, db);
            var task = db.Tasks.Single(t => t.Id == id);

            task.WhoId = pid;
            db.SubmitChanges();

            if (task.CoOwner != null)
            {
                gcm.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Tasks About Changed", $"{Util.UserFullName} has change the about person on a task delegated to you");
            }

            if (Util.UserPeopleId.HasValue)
            {
                gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH);
            }
        }
示例#17
0
        public static void DeclineTask(int id, string reason, string host, CMSDataContext db)
        {
            var gcm  = new GCMHelper(host, db);
            var task = db.Tasks.Single(t => t.Id == id);

            task.StatusId      = TaskStatusCode.Declined;
            task.DeclineReason = reason;

            db.SubmitChanges();
            db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task declined by {Util.UserFullName}", CreateEmailBody(task, host, db));

            gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Declined", $"{Util.UserFullName} declined a task");

            if (Util.UserPeopleId.HasValue)
            {
                gcm.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
            }
        }
示例#18
0
        public void UpdateTask()
        {
            var sb   = new StringBuilder();
            var task = DbUtil.Db.Tasks.Single(t => t.Id == Id);

            TaskModel.ChangeTask(sb, task, "Description", Description);
            TaskModel.ChangeTask(sb, task, "Due", Due);
            TaskModel.ChangeTask(sb, task, "Notes", Notes);
            TaskModel.ChangeTask(sb, task, "StatusId", StatusId);
            task.ForceCompleteWContact = ForceCompleteWContact;
            if (HttpContext.Current.User.IsInRole("AdvancedTask"))
            {
                TaskModel.ChangeTask(sb, task, "Project", Project);
            }

            task.Location = Location;
            if (Priority == 0)
            {
                task.Priority = null;
            }
            else
            {
                task.Priority = Priority;
            }
            DbUtil.Db.SubmitChanges();
            TaskModel.NotifyIfNeeded(sb, task);

            if (task.Owner.PeopleId == Util.UserPeopleId.Value)
            {
                if (task.CoOwner != null)
                {
                    GCMHelper.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Updated", $"{Util.UserFullName} updated a task delegated to you");
                }
            }
            else
            {
                GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Updated", $"{Util.UserFullName} updated a task you own");
            }


            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
        }
示例#19
0
        public static bool AcceptTask(User user, int id)
        {
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == id);

            if (task == null)
            {
                return(false);
            }

            task.StatusId = TaskStatusCode.Active;

            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task accepted by {user.Person.Name}", CreateEmailBody(task));

            GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Accepted", $"{user.Person.Name} accepted a task");

            if (user.PeopleId.HasValue)
            {
                GCMHelper.sendRefresh(user.PeopleId.Value, GCMHelper.TYPE_TASK);
            }

            return(true);
        }
示例#20
0
        public void CompleteTask(int id)
        {
            var task     = DbUtil.Db.Tasks.Single(t => t.Id == id);
            var sb       = new StringBuilder();
            var statusid = TaskStatusCode.Complete;

            ChangeTask(sb, task, "StatusId", statusid);
            NotifyIfNeeded(sb, task);
            DbUtil.Db.SubmitChanges();

            if (task.Owner.PeopleId == Util.UserPeopleId)
            {
                if (task.CoOwner != null)
                {
                    GCMHelper.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task they delegated to you");
                }
            }
            else
            {
                GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{Util.UserFullName} completed a task you delegated them");
            }

            GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK);
        }
示例#21
0
        public Task Delegate(int taskid, int toid, bool notify = true, bool forceCompleteWithContact = false)
        {
            if (toid == Util.UserPeopleId.Value)
            {
                return(null); // cannot delegate to self
            }
            var task = DbUtil.Db.Tasks.SingleOrDefault(t => t.Id == taskid);

            if (task == null)
            {
                return(null);
            }

            int previousDelegatee = task.CoOwnerId ?? 0;

            task.StatusId  = TaskStatusCode.Pending;
            task.CoOwnerId = toid;

            if (forceCompleteWithContact)
            {
                task.ForceCompleteWContact = true;
            }

            // if the owner's list is shared by the coowner
            // then put it in owner's list
            // otherwise put it in the coowner's inbox
            if (task.TaskList.TaskListOwners.Any(tlo => tlo.PeopleId == toid) || task.TaskList.CreatedBy == toid)
            {
                task.CoListId = task.ListId;
            }
            else
            {
                task.CoListId = InBoxId(toid);
            }

            Person toPerson = DbUtil.Db.LoadPersonById(toid);

            DbUtil.Db.SubmitChanges();
            DbUtil.Db.Email(task.Owner.EmailAddress, toPerson, $"Task delegated to you by {Util.UserFullName}", CreateEmailBody(task));

            if (notify)
            {
                if (previousDelegatee == 0) // No previous delegatee
                {
                    GCMHelper.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskid, "Task Delegated", $"{Util.UserFullName} delegated you a task");
                    GCMHelper.sendRefresh(task.Owner.PeopleId, GCMHelper.TYPE_TASK);
                }
                else // Had a previous delegatee
                {
                    if (previousDelegatee == Util.UserPeopleId.Value) // Delegatee redelegating
                    {
                        GCMHelper.sendRefresh(previousDelegatee, GCMHelper.TYPE_TASK);
                        GCMHelper.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskid, "Task Delegated", $"{Util.UserFullName} has delegated a task to you");
                        GCMHelper.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, taskid, "Task Redelegated", $"{Util.UserFullName} has redelegated a task you delegated to them");
                    }
                    else // Owner, with previous delegatee
                    {
                        GCMHelper.sendRefresh(task.Owner.PeopleId, GCMHelper.TYPE_TASK);
                        GCMHelper.sendNotification(toPerson.PeopleId, GCMHelper.TYPE_TASK, taskid, "Task Delegated", $"{Util.UserFullName} delegated you a task");
                        GCMHelper.sendNotification(previousDelegatee, GCMHelper.TYPE_TASK, 0, "Task Redelegated", $"{Util.UserFullName} has redelegated a task to someone else");
                    }
                }
            }

            return(task);
        }
示例#22
0
        public static int AddCompletedContact(int taskId, User user, string host, CMSDataContext db)
        {
            var gcm  = new GCMHelper(host, db);
            var task = db.Tasks.Single(t => t.Id == taskId);

            var c = new Contact {
                CreatedDate = DateTime.Now, ContactDate = DateTime.Now
            };

            var min = db.Ministries.SingleOrDefault(m => m.MinistryName == task.Project);

            if (min != null)
            {
                c.MinistryId = min.MinistryId;
            }

            if (task.WhoId.HasValue)
            {
                c.contactees.Add(new Contactee {
                    PeopleId = task.WhoId.Value
                });
            }

            if (user.PeopleId.HasValue)
            {
                c.contactsMakers.Add(new Contactor {
                    PeopleId = user.PeopleId.Value
                });
            }

            c.Comments            = task.Notes;
            task.CompletedContact = c;
            task.StatusId         = TaskStatusCode.Complete;

            if (task.CoOwnerId == user.PeopleId)
            {
                db.Email(task.CoOwner.EmailAddress, task.Owner, $"Task completed with a Contact by {user.Name}", CreateEmailBody(task, host, db));
            }
            else if (task.CoOwnerId != null)
            {
                db.Email(task.Owner.EmailAddress, task.CoOwner, $"Task completed with a Contact by {user.Name}", CreateEmailBody(task, host, db));
            }

            task.CompletedOn = c.ContactDate;

            db.SubmitChanges();

            if (task.Owner.PeopleId == user.PeopleId)
            {
                if (task.CoOwner != null)
                {
                    gcm.sendNotification(task.CoOwner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{user.Name} completed a task they delegated to you");
                }
            }
            else
            {
                gcm.sendNotification(task.Owner.PeopleId, GCMHelper.TYPE_TASK, task.Id, "Task Complete", $"{user.Name} completed a task you delegated them");
            }

            if (user.PeopleId.HasValue)
            {
                gcm.sendRefresh(user.PeopleId.Value, GCMHelper.TYPE_TASK);
            }

            return(c.ContactId);
        }