Пример #1
0
        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);
            }
        }