public static string GetTasksViewItem(RestCommand command, int) { TasksViewItem tasksViewItem = TasksView.GetTasksViewItem(command.LoginUser, ); if (tasksViewItem.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } return(tasksViewItem.GetXml("TasksViewItem", true)); }
public TasksViewItemProxy GetTask(int taskID) { TasksViewItem task = TasksView.GetTasksViewItem(TSAuthentication.GetLoginUser(), taskID); if (task.OrganizationID != TSAuthentication.OrganizationID) { return(null); } return(task.GetProxy()); }
override protected void GetNextRecord() { TasksViewItem task = TasksView.GetTasksViewItem(_loginUser, _itemIDList[_rowIndex]); _lastItemID = task.TaskID; UpdatedItems.Add((int)_lastItemID); StringBuilder builder = new StringBuilder(); builder.AppendLine(task.Description + " " + task.Name + " " + task.DateCreated + " " + task.DateModified); DocText = builder.ToString(); _docFields.Clear(); AddDocField("TaskID", task.TaskID); AddDocField("Name", task.Name); DocDisplayName = task.Name; TaskSearch taskItem = new TaskSearch(task); AddDocField("**JSON", JsonConvert.SerializeObject(taskItem)); // How do we handle associations indexing? //TaskAssociationsView associations = new TaskAssociationsView(_loginUser); //associations.LoadByTaskIDOnly(task.TaskID); //foreach (TaskAssociationsViewItem association in associations) //{ // object o = value.Row["CustomValue"]; // string s = o == null || o == DBNull.Value ? "" : o.ToString(); // AddDocField(value.Row["Name"].ToString(), s); //} DocFields = _docFields.ToString(); DocIsFile = false; DocName = task.TaskID.ToString(); try { DocCreatedDate = (DateTime)task.Row["DateCreated"]; DocModifiedDate = (DateTime)task.Row["DateModified"]; } catch (Exception) { } }
private void ProcessReminder(Reminder reminder) { Logs.WriteLine(); Logs.WriteEvent("***********************************************************************************"); Logs.WriteEvent("Processing Reminder ReminderID: " + reminder.ReminderID.ToString()); Logs.WriteData(reminder.Row); Logs.WriteLine(); Logs.WriteEvent("***********************************************************************************"); MailMessage message; UsersViewItem user = UsersView.GetUsersViewItem(LoginUser, (int)reminder.UserID); if (user == null) { return; } string description = ""; switch (reminder.RefType) { case ReferenceType.Organizations: OrganizationsViewItem org = OrganizationsView.GetOrganizationsViewItem(LoginUser, reminder.RefID); if (org == null) { return; } message = EmailTemplates.GetReminderCustomerEmail(LoginUser, reminder, user, org); description = String.Format("Reminder sent to {0} for Organization {1}", message.To.ToString(), org.Name); Logs.WriteEvent(description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Organizations, org.OrganizationID, description); break; case ReferenceType.Tickets: TicketsViewItem ticket = TicketsView.GetTicketsViewItem(LoginUser, reminder.RefID); if (ticket == null) { return; } message = EmailTemplates.GetReminderTicketEmail(LoginUser, reminder, user, ticket); EmailTemplates.ReplaceEmailRecipientParameters(LoginUser, message, Tickets.GetTicket(LoginUser, ticket.TicketID), reminder.UserID); //vv TeamSupport.Data.Action action = (new Actions(LoginUser)).AddNewAction(); action.ActionTypeID = null; action.Name = "Reminder"; action.ActionSource = "Reminder"; action.SystemActionTypeID = SystemActionType.Reminder; action.Description = String.Format("<p>The following is a reminder for {0} {1}:</p><p> </p><p>{2}</p>", user.FirstName, user.LastName, reminder.Description); action.IsVisibleOnPortal = false; action.IsKnowledgeBase = false; action.TicketID = ticket.TicketID; action.Collection.Save(); description = String.Format("Reminder sent to {0} for Ticket {1}", message.To.ToString(), ticket.TicketNumber.ToString()); Logs.WriteEvent(description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tickets, ticket.TicketID, description); break; case ReferenceType.Contacts: ContactsViewItem contact = ContactsView.GetContactsViewItem(LoginUser, reminder.RefID); if (contact == null) { return; } message = EmailTemplates.GetReminderContactEmail(LoginUser, reminder, user, contact); description = String.Format("Reminder sent to {0} for Contact {1}", message.To.ToString(), contact.FirstName + " " + contact.LastName); Logs.WriteEvent(description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, reminder.RefType, reminder.RefID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, contact.UserID, description); break; case ReferenceType.Tasks: TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, reminder.RefID); if (task == null || task.IsComplete) { reminder.IsDismissed = true; reminder.Collection.Save(); return; } message = EmailTemplates.GetReminderTaskEmail(LoginUser, reminder, user, task); description = String.Format("Reminder sent to {0} for Task {1}", message.To.ToString(), task.Name); Logs.WriteEvent("ver. 05162017: " + description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)reminder.UserID, description); TaskAssociations taskAssociations = new TaskAssociations(LoginUser); taskAssociations.LoadByTaskIDOnly(task.TaskID); foreach (TaskAssociation taskAssociation in taskAssociations) { if (taskAssociation.RefType == (int)ReferenceType.Tickets) { TeamSupport.Data.Action taskAction = (new Actions(LoginUser)).AddNewAction(); taskAction.ActionTypeID = null; taskAction.Name = "Reminder"; taskAction.ActionSource = "Reminder"; taskAction.SystemActionTypeID = SystemActionType.Reminder; taskAction.Description = String.Format("<p>The following is a reminder for {0} {1}:</p><p> </p><p>{2}</p>", user.FirstName, user.LastName, reminder.Description); taskAction.IsVisibleOnPortal = false; taskAction.IsKnowledgeBase = false; taskAction.TicketID = taskAssociation.RefID; try { taskAction.Collection.Save(); } catch (Exception ex) { Logs.WriteEvent("Ex Reminder Action.Save: " + ex.StackTrace); } } } break; default: message = null; break; } if (message == null) { return; } reminder.HasEmailSent = true; reminder.Collection.Save(); if (Emails.IsEmailDisabled(LoginUser, user.UserID, "Reminders")) { Logs.WriteEvent("Message skipped due to disabled user setting."); } else { MailAddress address = new MailAddress(user.Email, user.FirstName + " " + user.LastName); Logs.WriteEvent("Mail Address: " + address.ToString()); message.To.Add(address); EmailTemplates.ReplaceMailAddressParameters(message); Emails.AddEmail(LoginUser, reminder.OrganizationID, null, message.Subject, message); Logs.WriteEvent("Message queued"); } }
private void ProcessOldUser(int taskID, int modifierID, int oldUserID) { TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, taskID); try { User modifier = Users.GetUser(LoginUser, modifierID); if (task == null) { Logs.WriteEvent("Unable to find Task, TaskID: " + taskID.ToString()); return; } if (modifier == null) { Logs.WriteEvent("Unable to find Modifying User, UserID: " + modifierID.ToString()); return; } Organization taskOrganization = Organizations.GetOrganization(LoginUser, task.OrganizationID); if (taskOrganization == null) { Logs.WriteEvent("Task's Organization IS NULL!!!!"); return; } User oldUser = Users.GetUser(LoginUser, oldUserID); UsersViewItem owner = null; if (task.UserID != null) { owner = UsersView.GetUsersViewItem(LoginUser, (int)task.UserID); } if (Emails.IsEmailDisabled(LoginUser, oldUser.UserID, "Tasks")) { return; } MailMessage message = EmailTemplates.GetTaskOldUser(LoginUser, UsersView.GetUsersViewItem(LoginUser, modifierID), UsersView.GetUsersViewItem(LoginUser, (int)oldUserID), owner, task); //if (oldUser.UserID == modifier.UserID) //{ // User creator = Users.GetUser(LoginUser, (int)task.CreatorID); // message.To.Add(GetMailAddress(creator.Email, creator.FirstLastName)); //} //else //{ message.To.Add(GetMailAddress(oldUser.Email, oldUser.FirstLastName)); //} //message.Subject = message.Subject + " [pvt]"; //EmailTemplates.ReplaceEmailRecipientParameters(LoginUser, message, ticket, owner.UserID, owner.OnlyEmailAfterHours); EmailTemplates.ReplaceMailAddressParameters(message); String description = String.Format("Task old user notification sent to {0} for Task {1}", message.To.ToString(), task.Name); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)task.UserID, description); //string emailReplyToAddress = GetEmailReplyToAddress(LoginUser, ticket); //AddMessage(taskOrganization, "Ticket Update Request [" + ticket.TicketNumber.ToString() + "]", message, emailReplyToAddress); Emails.AddEmail(LoginUser, task.OrganizationID, null, message.Subject, message); Logs.WriteEvent("Message queued"); } catch (Exception ex) { Logs.WriteEvent("Error with ProcessTaskComplete"); Logs.WriteException(ex); ExceptionLogs.LogException(LoginUser, ex, "ProcessTaskComplete", task.Row); } }
private void ProcessTaskAssigned(int taskID, int modifierID) { TasksViewItem task = TasksView.GetTasksViewItem(LoginUser, taskID); try { User modifier = Users.GetUser(LoginUser, modifierID); if (task == null) { Logs.WriteEvent("Unable to find Task, TaskID: " + taskID.ToString()); return; } if (modifier == null) { Logs.WriteEvent("Unable to find Modifying User, UserID: " + modifierID.ToString()); return; } if (task.UserID == null) { Logs.WriteEvent("Assigned Task User is null"); return; } Organization taskOrganization = Organizations.GetOrganization(LoginUser, task.OrganizationID); if (taskOrganization == null) { Logs.WriteEvent("Task's Organization IS NULL!!!!"); return; } User owner = Users.GetUser(LoginUser, (int)task.UserID); if (owner.UserID == modifier.UserID) { Logs.WriteEvent("Modifier and Owner are the same person."); return; } if (Emails.IsEmailDisabled(LoginUser, owner.UserID, "Tasks")) { return; } MailMessage message = EmailTemplates.GetTaskAssigned(LoginUser, UsersView.GetUsersViewItem(LoginUser, modifierID), UsersView.GetUsersViewItem(LoginUser, (int)task.UserID), task); message.To.Add(GetMailAddress(owner.Email, owner.FirstLastName)); //message.Subject = message.Subject + " [pvt]"; EmailTemplates.ReplaceMailAddressParameters(message); String description = String.Format("Task assigned notification sent to {0} for Task {1}", message.To.ToString(), task.Name); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Tasks, task.TaskID, description); ActionLogs.AddActionLog(LoginUser, ActionLogType.Insert, ReferenceType.Users, (int)task.UserID, description); //string emailReplyToAddress = GetEmailReplyToAddress(LoginUser, ticket); //AddMessage(taskOrganization, "Ticket Update Request [" + ticket.TicketNumber.ToString() + "]", message, emailReplyToAddress); Emails.AddEmail(LoginUser, task.OrganizationID, null, message.Subject, message); Logs.WriteEvent("Message queued"); } catch (Exception ex) { Logs.WriteEvent("Error with ProcessTaskAssigned"); Logs.WriteException(ex); ExceptionLogs.LogException(LoginUser, ex, "ProcessTaskModified", task.Row); } }