public TaskProxy SetDueDate(int taskID, string data) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); StringBuilder description = new StringBuilder(); TaskJsonInfo info = Newtonsoft.Json.JsonConvert.DeserializeObject <TaskJsonInfo>(data); DateTime dueDate = (DateTime)info.DueDate; if (task.DueDate == null) { description.Append(String.Format("Changed Due Date from \"{0}\" to \"{1}\".", "Unassigned", (dueDate).ToString())); } else { description.Append(String.Format("Changed Due Date from \"{0}\" to \"{1}\".", ((DateTime)task.DueDate).ToString(), (dueDate).ToString())); } task.DueDate = DataUtils.DateToUtc(loginUser, dueDate); task.Collection.Save(); TaskLogs.AddTaskLog(loginUser, taskID, description.ToString()); if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } return(task.GetProxy()); }
public void ClearReminderDate(int taskID) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Reminder reminder = Reminders.GetReminderByTaskID(loginUser, taskID); StringBuilder description = new StringBuilder(); description.Append("Changed Reminder Date to None."); reminder.Delete(); reminder.Collection.Save(); TaskLogs.AddTaskLog(loginUser, taskID, "Reminder deleted"); SendModifiedNotification(loginUser.UserID, taskID); }
public ReminderProxy SetReminderDueDate(int taskID, string data) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Reminder reminder = Reminders.GetReminderByTaskID(loginUser, taskID); StringBuilder description = new StringBuilder(); Task task = Tasks.GetTask(loginUser, taskID); TaskJsonInfo info = Newtonsoft.Json.JsonConvert.DeserializeObject <TaskJsonInfo>(data); DateTime reminderDueDate = (DateTime)info.Reminder; if (reminder != null) { if (reminder.DueDate == null) { description.Append(String.Format("Changed Reminder from \"{0}\" to \"{1}\".", "Unassigned", (reminderDueDate).ToString())); } else { description.Append(String.Format("Changed Reminder from \"{0}\" to \"{1}\".", ((DateTime)reminder.DueDate).ToString(), (reminderDueDate).ToString())); } reminder.DueDate = DataUtils.DateToUtc(loginUser, reminderDueDate); reminder.IsDismissed = false; reminder.HasEmailSent = false; reminder.Collection.Save(); TaskLogs.AddTaskLog(loginUser, taskID, description.ToString()); } else { if (reminder == null) { if (task.UserID == null) { reminder = CreateReminder(loginUser, taskID, task.Name, DataUtils.DateToUtc(loginUser, reminderDueDate), false); } else { reminder = CreateReminder(loginUser, taskID, task.Name, DataUtils.DateToUtc(loginUser, reminderDueDate), false, (int)task.UserID); } task.ReminderID = reminder.ReminderID; task.Collection.Save(); } } if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } return(reminder.GetProxy()); }
public bool AddAssociation(int taskID, int refID, int refType) { LoginUser loginUser = TSAuthentication.GetLoginUser(); try { TaskAssociation taskAssociation = (new TaskAssociations(loginUser).AddNewTaskAssociation()); taskAssociation.TaskID = taskID; taskAssociation.RefID = refID; taskAssociation.RefType = refType; taskAssociation.DateCreated = DateTime.UtcNow; taskAssociation.CreatorID = loginUser.UserID; taskAssociation.Collection.Save(); string description = String.Format("{0} added task association to {1}.", TSAuthentication.GetUser(loginUser).FirstLastName, Enum.GetName(typeof(ReferenceType), refType)); TaskLogs.AddTaskLog(loginUser, taskID, description); Task task = Tasks.GetTask(loginUser, taskID); if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } if (refType == (int)ReferenceType.Contacts) { TeamSupport.Data.User user = Users.GetUser(loginUser, refID); taskAssociation = (new TaskAssociations(loginUser).AddNewTaskAssociation()); taskAssociation.TaskID = taskID; taskAssociation.RefID = user.OrganizationID; taskAssociation.RefType = (int)ReferenceType.Organizations; taskAssociation.DateCreated = DateTime.UtcNow; taskAssociation.CreatorID = loginUser.UserID; try { taskAssociation.Collection.Save(); } catch (Exception e) { //TaskAssociation do not allow duplicates. This could happen when the company is already associated with the task. } } return(true); } catch (Exception e) { return(false); } }
public void ClearDueDate(int taskID) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); StringBuilder description = new StringBuilder(); description.Append("Changed Due Date to None."); task.DueDate = null; task.Collection.Save(); TaskLogs.AddTaskLog(loginUser, taskID, description.ToString()); if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } }
public int SetUser(int taskID, int value) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); Reminder reminder = Reminders.GetReminderByTaskID(loginUser, taskID); if (task.UserID != null && loginUser.UserID != task.UserID && value != task.UserID) { SendOldUserNotification(loginUser.UserID, (int)task.UserID, task.TaskID); } if (value != -1 && loginUser.UserID != value && value != task.UserID) { SendAssignedNotification(loginUser.UserID, task.TaskID); } //User is being set to unassigned if (value == -1) { if (reminder != null) { reminder.Delete(); reminder.Collection.Save(); task.ReminderID = null; } task.UserID = null; } else { if (reminder != null) { reminder.UserID = value; reminder.Collection.Save(); } task.UserID = value; } task.Collection.Save(); User u = Users.GetUser(loginUser, value); string description = String.Format("{0} set task user to {1} ", TSAuthentication.GetUser(loginUser).FirstLastName, u == null ? "Unassigned" : u.FirstLastName); TaskLogs.AddTaskLog(loginUser, taskID, description); return(value); }
public TaskCompletionStatus SetTaskIsCompleted(int taskID, bool value) { TaskCompletionStatus result = new TaskCompletionStatus(false, value); LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); task.IsComplete = value; //if a user is attempting to complete a task check for incomplete subtasks first if (value) { if (GetIncompleteSubtasks(taskID)) { result.IncompleteSubtasks = true; result.Value = !value; return(result); } task.DateCompleted = DateTime.UtcNow; result.DateCompleted = task.DateCompleted; } else { result.IncompleteSubtasks = false; result.Value = value; task.DateCompleted = null; } //We are clearing completion comments as they could or not be set in next call. task.CompletionComment = null; task.Collection.Save(); string description = String.Format("{0} set task is complete to {1} ", TSAuthentication.GetUser(loginUser).FirstLastName, value); TaskLogs.AddTaskLog(loginUser, taskID, description); if (task.IsComplete && (loginUser.UserID != task.CreatorID || (task.UserID != null && loginUser.UserID != task.UserID))) { SendCompletedNotification(loginUser.UserID, task.TaskID); } else if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } return(result); }
public string SetDescription(int taskID, string value) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); task.Description = value; task.Collection.Save(); string description = String.Format("{0} set task description to {1} ", TSAuthentication.GetUser(loginUser).FirstLastName, value); TaskLogs.AddTaskLog(loginUser, taskID, description); if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.TaskID); } return(value != "" ? value : "Empty"); }
public TaskCompletionStatus AddTaskCompleteComment(int taskID, string comment) { LoginUser loginUser = TSAuthentication.GetLoginUser(); Task task = Tasks.GetTask(loginUser, taskID); task.CompletionComment = comment; task.Collection.Save(); //string description = String.Format(@"{0} added task complete note: ""{1}""", TSAuthentication.GetUser(loginUser).FirstLastName, comment); string description = String.Format(@"{0} added task complete note.", TSAuthentication.GetUser(loginUser).FirstLastName); TaskLogs.AddTaskLog(loginUser, taskID, description); TaskCompletionStatus result = new TaskCompletionStatus(false, true); result.DateCompleted = task.DateCompleted; result.CompletionComment = task.CompletionComment; return(result); }
public void DeleteAssociation(int reminderID, int refID, ReferenceType refType) { try { LoginUser loginUser = TSAuthentication.GetLoginUser(); TaskAssociations associations = new TaskAssociations(loginUser); associations.DeleteAssociation(reminderID, refID, refType); string description = String.Format("{0} deleted task association to {1} ", TSAuthentication.GetUser(loginUser).FirstLastName, Enum.GetName(typeof(ReferenceType), refType)); TaskLogs.AddTaskLog(loginUser, reminderID, description); Reminder task = Reminders.GetReminder(loginUser, reminderID); if (task.UserID != null && loginUser.UserID != task.UserID) { SendModifiedNotification(loginUser.UserID, task.ReminderID); } } catch (Exception ex) { DataUtils.LogException(UserSession.LoginUser, ex); } }
public TaskProxy NewTask(string data) { TaskJsonInfo info = Newtonsoft.Json.JsonConvert.DeserializeObject <TaskJsonInfo>(data); LoginUser loginUser = TSAuthentication.GetLoginUser(); Task newTask = (new Tasks(loginUser)).AddNewTask(); newTask.ParentID = info.ParentID; newTask.OrganizationID = TSAuthentication.OrganizationID; newTask.Name = info.Name; newTask.Description = info.Description; newTask.UserID = info.UserID; newTask.IsComplete = info.IsComplete; if (newTask.IsComplete) { newTask.DateCompleted = DateTime.UtcNow; } newTask.DueDate = DataUtils.DateToUtc(loginUser, info.DueDate); newTask.Collection.Save(); if (info.Reminder != null) { Reminder reminder = null; if (newTask.UserID == null) { reminder = CreateReminder(loginUser, newTask.TaskID, info.Name, DataUtils.DateToUtc(loginUser, (DateTime)info.Reminder), false); } else { reminder = CreateReminder(loginUser, newTask.TaskID, info.Name, DataUtils.DateToUtc(loginUser, (DateTime)info.Reminder), false, (int)newTask.UserID); } if (reminder != null) { Tasks taskHelper = new Tasks(loginUser); taskHelper.LoadByTaskID(newTask.TaskID); if (taskHelper.Any()) { taskHelper[0].ReminderID = reminder.ReminderID; taskHelper.Save(); } } } foreach (int ticketID in info.Tickets) { AddAssociation(newTask.TaskID, ticketID, (int)ReferenceType.Tickets); } foreach (int productID in info.Products) { AddAssociation(newTask.TaskID, productID, (int)ReferenceType.Products); } foreach (int CompanyID in info.Company) { AddAssociation(newTask.TaskID, CompanyID, (int)ReferenceType.Organizations); } foreach (int UserID in info.Contacts) { AddAssociation(newTask.TaskID, UserID, (int)ReferenceType.Contacts); } foreach (int groupID in info.Groups) { AddAssociation(newTask.TaskID, groupID, (int)ReferenceType.Groups); } foreach (int UserID in info.User) { AddAssociation(newTask.TaskID, UserID, (int)ReferenceType.Users); } foreach (int ActivityID in info.Activities) { Notes notes = new Notes(TSAuthentication.GetLoginUser()); notes.LoadByNoteID(ActivityID); if (notes.Count > 0) { var note = notes[0]; if (note.RefType == ReferenceType.Organizations) { AddAssociation(newTask.TaskID, ActivityID, (int)ReferenceType.CompanyActivity); } else if (note.RefType == ReferenceType.Users) { AddAssociation(newTask.TaskID, ActivityID, (int)ReferenceType.ContactActivity); } } } string description = String.Format("{0} created task.", TSAuthentication.GetUser(loginUser).FirstLastName); TaskLogs.AddTaskLog(loginUser, newTask.TaskID, description); if (newTask.UserID != null && loginUser.UserID != newTask.UserID) { SendAssignedNotification(loginUser.UserID, newTask.TaskID); } return(newTask.GetProxy()); }