public static string GetContactsViewItem(RestCommand command, int userID)
        {
            ContactsViewItem contactsViewItem = ContactsView.GetContactsViewItem(command.LoginUser, userID);

            if (contactsViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(contactsViewItem.GetXml("ContactsViewItem", true));
        }
Ejemplo n.º 2
0
        public static string DeleteContact(RestCommand command, int id)
        {
            ContactsViewItem user = ContactsView.GetContactsViewItem(command.LoginUser, id);

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

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

            Users.MarkUserDeleted(command.LoginUser, id);
            return(result);
        }
        private void SyncContactInformation(ContactsViewItem contact)
        {
            Logs.WriteEvent(string.Format("Processing contact {0}({1}) of organization {2}({3})", contact.Name, contact.UserID, contact.Organization, contact.OrganizationID));

            if (!string.IsNullOrEmpty(contact.Email))
            {
                string responseText     = string.Empty;
                string requestParameter = string.Format("{0}={1}", ContactObjects.Lookup.email.ToString(), contact.Email);
                string requestUrl       = string.Format("{0}person.json?{1}", _baseURI, requestParameter);
                responseText = CustomerInsightsUtilities.MakeHttpWebRequest(requestUrl, _securityToken, Logs, Settings, _currentContactApiCallsKey, ref _currentContactApiCalls);

                try
                {
                    if (!string.IsNullOrEmpty(responseText))
                    {
                        JObject jObject = JObject.Parse(responseText);
                        ContactObjects.RootObject contactInfo = JsonConvert.DeserializeObject <ContactObjects.RootObject>(jObject.ToString());
                        User currentContact = Users.GetUser(LoginUser, contact.UserID);
                        UpdateContactInformation(contactInfo, currentContact, (int)contact.OrganizationParentID);
                    }
                    else
                    {
                        Logs.WriteEvent("CustomerInsights did not return information.");
                    }
                }
                catch (Exception ex)
                {
                    Logs.WriteException(ex);
                }
            }
            else
            {
                Logs.WriteEvent("This contact does not have a email entered, can't get its CustomerInsights information.");
            }

            UpdateFullContactContactModified(contact.UserID);
        }
        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");
            }
        }
        protected override void GetNextRecord()
        {
            ContactsViewItem contact = ContactsView.GetContactsViewItem(_loginUser, _itemIDList[_rowIndex]);

            _lastItemID = contact.UserID;
            UpdatedItems.Add((int)_lastItemID);

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

            if (!string.IsNullOrWhiteSpace(contact.Email))
            {
                builder.AppendLine(Regex.Replace(contact.Email, "[,.]+", ""));
            }
            PhoneNumbers phoneNumbers = new PhoneNumbers(_loginUser);

            phoneNumbers.LoadByID(contact.UserID, ReferenceType.Users);
            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(contact.UserID, ReferenceType.Users);
            foreach (Address address in addresses)
            {
                builder.AppendLine(address.Description
                                   + " " + address.Addr1
                                   + " " + address.Addr2
                                   + " " + address.Addr3
                                   + " " + address.City
                                   + " " + address.State
                                   + " " + address.Zip
                                   + " " + address.Country);
            }

            EmailAddresses emailAddresses = new EmailAddresses(_loginUser);

            emailAddresses.LoadByRefID(contact.UserID, ReferenceType.Users);
            foreach (EmailAddress emailAddress in emailAddresses)
            {
                builder.AppendLine(Regex.Replace(emailAddress.Email, "[,.]+", ""));
            }

            _docFields.Clear();
            AddDocField("UserID", contact.UserID);
            AddDocField("OrganizationID", contact.OrganizationID);
            AddDocField("Organization", contact.Organization);
            AddDocField("Email", contact.Email);
            AddDocField("IsActive", contact.IsActive);

            if (string.IsNullOrWhiteSpace(contact.FirstName))
            {
                AddDocField("Name", contact.LastName);
                DocDisplayName = string.IsNullOrWhiteSpace(contact.FirstName) ? "" : contact.FirstName.Trim();
            }
            else
            {
                AddDocField("Name", contact.FirstName + " " + contact.LastName);
                DocDisplayName = contact.LastName.Trim() + (string.IsNullOrWhiteSpace(contact.FirstName) ? "" : ", " + contact.FirstName.Trim());
            }

            builder.AppendLine(Regex.Replace(DocDisplayName, "[^a-zA-Z0-9 -]", ""));
            builder.AppendLine(Regex.Replace(contact.Organization, "[^a-zA-Z0-9 -]", ""));

            DocText = builder.ToString();

            CustomerSearchContact contactItem = new CustomerSearchContact(contact);

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

            contactItem.openTicketCount = tickets.GetUserTicketCount(contact.UserID, 0);

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

            CustomValues customValues = new CustomValues(_loginUser);

            customValues.LoadByReferenceType(_organizationID, ReferenceType.Contacts, contact.UserID);

            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         = contact.UserID.ToString();
            DocCreatedDate  = (DateTime)contact.Row["DateCreated"];
            DocModifiedDate = (DateTime)contact.Row["DateModified"];
        }