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); } }
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"); } } }
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); }
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); } }
public static Task AddTaskAbout(CMSDataContext db, int familyId, int assignTo, string description) { var f = db.Families.Single(ff => ff.People.Any(mm => mm.FamilyId == familyId)); var primaryorchild = new[] { PositionInFamily.PrimaryAdult, PositionInFamily.Child }; var fmembers = (from p in db.People where p.FamilyId == familyId where primaryorchild.Contains(p.PositionInFamilyId) select p.Name).ToList(); var hh = db.LoadPersonById(f.HeadOfHouseholdId ?? 0); var t = new Task { OwnerId = assignTo, Description = description, Notes = "Family: " + string.Join(", ", fmembers), ForceCompleteWContact = true, ListId = Task.GetRequiredTaskList(db, "InBox", assignTo).Id, StatusId = TaskStatusCode.Active, }; hh.TasksAboutPerson.Add(t); if (db.Host.HasValue()) { var gcm = new GCMHelper(db.Host, db); gcm.sendRefresh(assignTo, GCMHelper.ACTION_REFRESH); } return(t); }
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); }
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); } }
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(); }
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); }
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); }
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); }
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); }
public void UpdateTask() { var sb = new StringBuilder(); var task = DbUtil.Db.Tasks.Single(t => t.Id == Id); ChangeTask(sb, task, "Description", Description); ChangeTask(sb, task, "LimitToRole", TaskLimitToRole.Value == "0" ? null : TaskLimitToRole.Value); ChangeTask(sb, task, "Due", Due); ChangeTask(sb, task, "Notes", Notes); ChangeTask(sb, task, "StatusId", TaskStatus.IntVal); task.ForceCompleteWContact = ForceCompleteWithContact; if (HttpContext.Current.User.IsInRole("AdvancedTask")) { ChangeTask(sb, task, "Project", Project); } task.Location = Location; if (Priority == 0) { task.Priority = null; } else { task.Priority = Priority; } DbUtil.Db.SubmitChanges(); NotifyIfNeeded(sb, task); if (task.Owner.PeopleId == Util.UserPeopleId) { 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"); } if (Util.UserPeopleId.HasValue) { GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.TYPE_TASK); } }
public static int AddTask(int pid, string text) { var task = new CmsData.Task { Description = text, OwnerId = pid, StatusId = TaskStatusCode.Active }; DbUtil.Db.Tasks.InsertOnSubmit(task); DbUtil.Db.SubmitChanges(); GCMHelper.sendRefresh(pid, GCMHelper.ACTION_REFRESH); return(task.Id); }
public static int AddTask(int pid, string text, string host, CMSDataContext db) { var gcm = new GCMHelper(host, db); var task = new CmsData.Task { Description = text, OwnerId = pid, StatusId = TaskStatusCode.Active }; db.Tasks.InsertOnSubmit(task); db.SubmitChanges(); gcm.sendRefresh(pid, GCMHelper.ACTION_REFRESH); return(task.Id); }
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); } }
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); } }
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); } }
public int AddTask(int pid, int listid, string text) { if (listid <= 0) { listid = InBoxId(pid); } var task = new Task { ListId = listid, Description = text, OwnerId = pid, StatusId = TaskStatusCode.Active }; DbUtil.Db.Tasks.InsertOnSubmit(task); DbUtil.Db.SubmitChanges(); GCMHelper.sendRefresh(pid, GCMHelper.ACTION_REFRESH); return(task.Id); }
internal void Delegate(int toPeopleId) { var owners = (from o in DbUtil.Db.Tasks where SelectedItem.Contains(o.Id) select o.OwnerId).Distinct().ToList(); var delegates = (from o in DbUtil.Db.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, 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"; 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(toPeopleId, GCMHelper.TYPE_TASK, 0, "Task Delegated", $"{Util.UserFullName} delegated you {taskString}"); if (Util.UserPeopleId.HasValue) { GCMHelper.sendRefresh(Util.UserPeopleId.Value, GCMHelper.ACTION_REFRESH); } DbUtil.Db.SubmitChanges(); }
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); }
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); }
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); }
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); }
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); }