public static string GetOrganizations(RestCommand command, bool orderByDateCreated = false, int?limitNumber = null)
        {
            OrganizationsView organizations = new OrganizationsView(command.LoginUser);
            bool hasBeenFiltered            = false;

            if (orderByDateCreated)
            {
                //This seems to be Zapier only
                organizations.LoadByParentID(command.Organization.OrganizationID, true, "DateCreated DESC", limitNumber);
                hasBeenFiltered = true;
            }
            else
            {
                try
                {
                    organizations.LoadByParentID(command.Organization.OrganizationID, true, command.Filters, command.PageNumber, command.PageSize);
                    hasBeenFiltered = true;
                }
                catch (Exception e)
                {
                    organizations = new OrganizationsView(command.LoginUser);
                    organizations.LoadByParentID(command.Organization.OrganizationID, true);
                    ExceptionLogs.LogException(command.LoginUser, e, "API", "RestOrganizations. RestGetOrganization(). SQL filtering generation failed, fell into old method (no filters?).");
                }
            }
            return(organizations.GetXml("Customers", "Customer", true, !hasBeenFiltered ? command.Filters : new System.Collections.Specialized.NameValueCollection(), command.IsPaging));
        }
Example #2
0
        public static string GetOrganizationsViewItem(RestCommand command, int organizationID)
        {
            OrganizationsViewItem organizationsViewItem = OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organizationID);

            if (organizationsViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(organizationsViewItem.GetXml("OrganizationsViewItem", true));
        }
Example #3
0
        override protected void LoadData()
        {
            OrganizationsView organizations = new OrganizationsView(_loginUser);

            organizations.LoadForIndexing(_organizationID, _maxCount, _isRebuilding);
            foreach (OrganizationsViewItem organization in organizations)
            {
                _itemIDList.Add(organization.OrganizationID);
            }
        }
Example #4
0
        public static string GetOrganizationsView(RestCommand command)
        {
            OrganizationsView organizationsView = new OrganizationsView(command.LoginUser);

            organizationsView.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(organizationsView.GetXml("OrganizationsView", "OrganizationsViewItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
        public static string CreateOrganization(RestCommand command)
        {
            Addresses addresses = new Addresses(command.LoginUser);
            Address   address   = addresses.AddNewAddress();

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

            Organizations organizations = new Organizations(command.LoginUser);
            Organization  organization  = organizations.AddNewOrganization();

            organization.ParentID = command.Organization.OrganizationID;
            organization.IsActive = true;
            organization.FullReadFromXml(command.Data, true, ref phoneNumber, ref address);
            organization.NeedsIndexing = true;
            organization.Collection.Save();
            organization.UpdateCustomFieldsFromXml(command.Data);

            if (!String.IsNullOrEmpty(phoneNumber.Number) || !String.IsNullOrEmpty(phoneNumber.Extension))
            {
                phoneNumber.RefType = ReferenceType.Organizations;
                phoneNumber.RefID   = organization.OrganizationID;
                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.Organizations;
                address.RefID   = organization.OrganizationID;
                addresses.Save();
            }

            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organization.OrganizationID).GetXml("Customer", true));
        }
        public static string GetVersionOrganizations(RestCommand command, int versionID, bool orderByDateCreated = false)
        {
            ProductVersionsViewItem item = ProductVersionsView.GetProductVersionsViewItem(command.LoginUser, versionID);

            if (item == null || item.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            OrganizationsView organizations = new OrganizationsView(command.LoginUser);

            if (orderByDateCreated)
            {
                organizations.LoadByVersionID(versionID, "op.DateCreated DESC");
            }
            else
            {
                organizations.LoadByVersionID(versionID);
            }
            return(organizations.GetXml("Customers", "Customer", true, command.Filters));
        }
        public static string RemoveTicketOrganization(RestCommand command, int ticketIDOrNumber, int organizationID)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

            if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Organization organization = Organizations.GetOrganization(command.LoginUser, organizationID);

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

            Tickets tickets = new Tickets(command.LoginUser);

            tickets.RemoveOrganization(organizationID, ticket.TicketID);
            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organizationID).GetXml("Customer", true));
        }
        public static string GetTicketOrganizations(RestCommand command, int ticketIDOrNumber, bool orderByDateCreated = false)
        {
            TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber);

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

            if (orderByDateCreated)
            {
                organizations.LoadByTicketID(ticket.TicketID, "ot.DateCreated DESC");
            }
            else
            {
                organizations.LoadByTicketID(ticket.TicketID);
            }
            return(organizations.GetXml("Customers", "Customer", true, command.Filters));
        }
        public static string RemoveOrganizationProduct(RestCommand command, int organizationID, int productID)
        {
            Organization organization = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (organization == null || organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            Product product = Products.GetProduct(command.LoginUser, productID);

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

            Products products = new Products(command.LoginUser);

            products.RemoveCustomer(organizationID, productID);
            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organizationID).GetXml("Customer", true));
        }
        public static string UpdateOrganization(RestCommand command, int organizationID)
        {
            Organization organization = Organizations.GetOrganization(command.LoginUser, organizationID);

            if (organization == null)
            {
                throw new RestException(HttpStatusCode.BadRequest);
            }
            if (organization.ParentID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }

            organization.ReadFromXml(command.Data, false);
            SetFieldIdsByName(command, ref organization);

            organization.Collection.Save();
            organization.UpdateCustomFieldsFromXml(command.Data);

            return(OrganizationsView.GetOrganizationsViewItem(command.LoginUser, organization.OrganizationID).GetXml("Customer", 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");
            }
        }
Example #12
0
        override protected void GetNextRecord()
        {
            OrganizationsViewItem organization = OrganizationsView.GetOrganizationsViewItem(_loginUser, _itemIDList[_rowIndex]);

            _lastItemID = organization.OrganizationID;
            UpdatedItems.Add((int)_lastItemID);

            StringBuilder builder             = new StringBuilder();
            List <CustomerSearchPhone> phones = new List <CustomerSearchPhone>();
            PhoneNumbers phoneNumbers         = new PhoneNumbers(_loginUser);

            phoneNumbers.LoadByID(organization.OrganizationID, ReferenceType.Organizations);
            foreach (PhoneNumber number in phoneNumbers)
            {
                phones.Add(new CustomerSearchPhone(number));
                builder.AppendLine(Regex.Replace(number.Number, "[^0-9]", ""));
            }

            Addresses addresses = new Addresses(_loginUser);

            addresses.LoadByID(organization.OrganizationID, ReferenceType.Organizations);
            foreach (Address address in addresses)
            {
                builder.AppendLine(address.Description
                                   + " " + address.Addr1
                                   + " " + address.Addr2
                                   + " " + address.Addr3
                                   + " " + address.City
                                   + " " + address.State
                                   + " " + address.Zip
                                   + " " + address.Country);
            }

            builder.AppendLine(Regex.Replace(organization.Name, "[^a-zA-Z0-9 -]", ""));

            DocText = builder.ToString();
            _docFields.Clear();
            AddDocField("OrganizationID", organization.OrganizationID);
            AddDocField("Name", organization.Name);
            AddDocField("Description", organization.Description);
            AddDocField("Website", organization.Website);
            AddDocField("IsActive", organization.IsActive);
            AddDocField("PrimaryContact", organization.PrimaryContact);
            AddDocField("IsParent", Organizations.GetIsParent(_loginUser, organization.OrganizationID));

            CustomerSearchCompany companyItem = new CustomerSearchCompany(organization);

            companyItem.phones = phones.ToArray();
            TicketsView tickets = new TicketsView(_loginUser);

            companyItem.openTicketCount = tickets.GetOrganizationTicketCount(organization.OrganizationID, 0);

            AddDocField("**JSON", JsonConvert.SerializeObject(companyItem));

            CustomValues customValues = new CustomValues(_loginUser);

            customValues.LoadByReferenceType(_organizationID, ReferenceType.Organizations, organization.OrganizationID);

            foreach (CustomValue value in customValues)
            {
                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         = organization.OrganizationID.ToString();
            DocDisplayName  = string.IsNullOrWhiteSpace(organization.Name) ? "" : organization.Name.Trim();
            DocCreatedDate  = (DateTime)organization.Row["DateCreated"];
            DocModifiedDate = (DateTime)organization.Row["DateModified"];
        }