public static string GetUsersViewItem(RestCommand command, int userID)
        {
            UsersViewItem usersViewItem = UsersView.GetUsersViewItem(command.LoginUser, userID);

            if (usersViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(usersViewItem.GetXml("UsersViewItem", true));
        }
示例#2
0
        public static string DeleteUser(RestCommand command, int userID)
        {
            UsersViewItem user = UsersView.GetUsersViewItem(command.LoginUser, userID);

            if (user == null)
            {
                throw new RestException(HttpStatusCode.BadRequest);
            }
            Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID);

            if (organization.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            string result = user.GetXml("User", true);

            Users.MarkUserDeleted(command.LoginUser, userID);
            return(result);
        }
示例#3
0
        public static string UpdateUser(RestCommand command, int userID)
        {
            User user = Users.GetUser(command.LoginUser, userID);

            if (user == null)
            {
                throw new RestException(HttpStatusCode.BadRequest);
            }
            Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID);

            if (organization.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            user.ReadFromXml(command.Data, false);
            user.Collection.Save();
            user.UpdateCustomFieldsFromXml(command.Data);
            return(UsersView.GetUsersViewItem(command.LoginUser, user.UserID).GetXml("User", true));
        }
示例#4
0
        public static string SubscribeToTicket(RestCommand command, int ticketIDOrNumber, int userId)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            UsersViewItem subscribingUser = UsersView.GetUsersViewItem(command.LoginUser, userId);

            if (subscribingUser == null || subscribingUser.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            Subscriptions.AddSubscription(command.LoginUser, userId, ReferenceType.Tickets, ticket.TicketID);

            return(ticket.GetXml("Ticket", true));
        }
        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>&nbsp;</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>&nbsp;</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");
            }
        }
示例#6
0
        public static string CreateUser(RestCommand command)
        {
            if (Organizations.GetUserCount(command.LoginUser, command.LoginUser.OrganizationID) >= command.Organization.UserSeats)
            {
                throw new RestException(HttpStatusCode.Forbidden, "You are already at your maximum user seat count for your license.");
            }
            Addresses addresses = new Addresses(command.LoginUser);
            Address   address   = addresses.AddNewAddress();

            PhoneNumbers phoneNumbers = new PhoneNumbers(command.LoginUser);
            PhoneNumber  phoneNumber  = phoneNumbers.AddNewPhoneNumber();

            Users users = new Users(command.LoginUser);
            User  user  = users.AddNewUser();

            user.FullReadFromXml(command.Data, true, ref phoneNumber, ref address);
            if (String.IsNullOrWhiteSpace(user.FirstName))
            {
                throw new RestException(HttpStatusCode.BadRequest, "FirstName is required.");
            }
            ;
            if (String.IsNullOrWhiteSpace(user.LastName))
            {
                throw new RestException(HttpStatusCode.BadRequest, "LastName is required.");
            }
            ;
            if (String.IsNullOrWhiteSpace(user.Email) || user.Email.IndexOf('@') < 0 || user.Email.IndexOf('.') < 0 || !users.IsEmailValid(user.Email, -1, command.LoginUser.OrganizationID))
            {
                throw new RestException(HttpStatusCode.BadRequest, "Email is invalid.");
            }
            ;
            user.OrganizationID       = command.LoginUser.OrganizationID;
            user.ActivatedOn          = DateTime.UtcNow;
            user.LastLogin            = DateTime.UtcNow.AddHours(-1);
            user.LastActivity         = DateTime.UtcNow.AddHours(-1);
            user.EnforceSingleSession = true;
            user.NeedsIndexing        = true;
            user.Collection.Save();
            user.UpdateCustomFieldsFromXml(command.Data);

            if (!String.IsNullOrEmpty(phoneNumber.Number) || !String.IsNullOrEmpty(phoneNumber.Extension))
            {
                phoneNumber.RefType = ReferenceType.Users;
                phoneNumber.RefID   = user.UserID;
                phoneNumbers.Save();
            }

            if (!String.IsNullOrEmpty(address.Description) ||
                !String.IsNullOrEmpty(address.Addr1) ||
                !String.IsNullOrEmpty(address.Addr2) ||
                !String.IsNullOrEmpty(address.Addr3) ||
                !String.IsNullOrEmpty(address.City) ||
                !String.IsNullOrEmpty(address.Country) ||
                !String.IsNullOrEmpty(address.Description) ||
                !String.IsNullOrEmpty(address.State) ||
                !String.IsNullOrEmpty(address.Zip))
            {
                address.RefType = ReferenceType.Users;
                address.RefID   = user.UserID;
                addresses.Save();
            }

            return(UsersView.GetUsersViewItem(command.LoginUser, user.UserID).GetXml("User", true));
        }
示例#7
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);
            }
        }
示例#8
0
        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);
            }
        }