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)); }
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); }
public static string RemoveTicketContact(RestCommand command, int ticketIDOrNumber, int contactID) { TicketsViewItem ticket = TicketsView.GetTicketsViewItemByIdOrNumber(command.LoginUser, ticketIDOrNumber); if (ticket == null || ticket.OrganizationID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } User user = Users.GetUser(command.LoginUser, contactID); Organization organization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID); if (organization == null || organization.ParentID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } Tickets tickets = new Tickets(command.LoginUser); tickets.RemoveContact(user.UserID, ticket.TicketID); return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", 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> </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"); } }
public static string UpdateContact(RestCommand command, int id) { User user = Users.GetUser(command.LoginUser, id); User oldUser = Users.GetUser(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); } bool allowOrganizationIdUpdate = true; user.ReadFromXml(command.Data, false, allowOrganizationIdUpdate); if (user.CryptedPassword != oldUser.CryptedPassword) { user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(user.CryptedPassword, "MD5"); } bool isChangingOrganizationId = oldUser.OrganizationID != user.OrganizationID; if (isChangingOrganizationId) { Organization newOrganization = Organizations.GetOrganization(command.LoginUser, user.OrganizationID); if (newOrganization.ParentID != command.Organization.OrganizationID) { throw new RestException(HttpStatusCode.Unauthorized); } //Let's follow the same reflexes as the UI (..\webapp\app_code\customerservice.cs SetContactCompany()) Tickets t = new Tickets(command.LoginUser); t.LoadByContact(id); foreach (Ticket tix in t) { tix.Collection.RemoveContact(id, tix.TicketID); } user.PortalAutoReg = false; user.Collection.Save(); foreach (Ticket tix in t) { tix.Collection.AddContact(id, tix.TicketID); } EmailPosts ep = new EmailPosts(command.LoginUser); ep.LoadByRecentUserID(id); ep.DeleteAll(); ep.Save(); } else { user.Collection.Save(); } user.UpdateCustomFieldsFromXml(command.Data); return(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true)); }
public static string CreateContact(RestCommand command, int?organizationID) { 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.IsActive = true; user.FullReadFromXml(command.Data, true, ref phoneNumber, ref address); if (organizationID == null && user.OrganizationID == 0) { if (!String.IsNullOrEmpty(user.Email) && user.Email.Contains("@")) { Organizations matchDomainCompany = new Organizations(command.LoginUser); matchDomainCompany.LoadFirstDomainMatch(command.LoginUser.OrganizationID, user.Email.Substring(user.Email.LastIndexOf("@") + 1)); if (!matchDomainCompany.IsEmpty) { user.OrganizationID = matchDomainCompany[0].OrganizationID; } } if (user.OrganizationID == 0) { user.OrganizationID = Organizations.GetUnknownCompanyID(command.LoginUser); } } else if (organizationID != null) { user.OrganizationID = (int)organizationID; } user.ActivatedOn = DateTime.UtcNow; user.LastLogin = DateTime.UtcNow; user.LastActivity = DateTime.UtcNow.AddHours(-1); user.IsPasswordExpired = true; user.NeedsIndexing = true; if (!string.IsNullOrEmpty(user.CryptedPassword)) { user.CryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(user.CryptedPassword, "MD5"); } 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(ContactsView.GetContactsViewItem(command.LoginUser, user.UserID).GetXml("Contact", true)); }
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"]; }