public static ContactsViewItem GetContactsViewItem(LoginUser loginUser, int userID)
        {
            ContactsView contactsView = new ContactsView(loginUser);

            contactsView.LoadByUserID(userID);
            if (contactsView.IsEmpty)
            {
                return(null);
            }
            else
            {
                return(contactsView[0]);
            }
        }
 public ContactsViewItem(DataRow row, ContactsView contactsView) : base(row, contactsView)
 {
     _contactsView = contactsView;
 }
Ejemplo n.º 3
0
        public void WriteToXml(XmlWriter writer, bool includeCustomFields, Tags tags = null)
        {
            foreach (FieldMapItem item in _baseCollection.FieldMap)
            {
                //hack: Adding this hack (second IF condition -the OR-) to allow the CryptedPassword to be displayed ONLY for this org. It is not available for any other. The plan is to have this as an option in the system but for now we need this asap.
                if (item.Select ||
                    (!item.Select && _baseCollection.LoginUser.OrganizationID == 931810 && item.PrivateName == "CryptedPassword"))
                {
                    string     s      = "";
                    DataColumn column = Row.Table.Columns[item.PrivateName];
                    if (Row[item.PrivateName] != DBNull.Value)
                    {
                        if (column.DataType == typeof(System.DateTime))
                        {
                            s = DateToLocal((DateTime)Row[item.PrivateName]).ToString("g", _baseCollection.LoginUser.CultureInfo);
                        }
                        else
                        {
                            s = Row[item.PrivateName].ToString();
                        }
                    }
                    string escape = SecurityElement.Escape(s).Replace(Convert.ToChar(0x0).ToString(), "").Replace(Convert.ToChar(0x1C).ToString(), "");
                    writer.WriteElementString(item.PublicName, escape);
                }
            }

            // Ticket 15640
            // Per a skype conversation with Jesus adding AMCO Sales (797841)
            if ((_baseCollection.LoginUser.OrganizationID == 566596 || _baseCollection.LoginUser.OrganizationID == 797841) && _baseCollection.TableName == "TicketsView")
            {
                Organizations customers = new Organizations(_baseCollection.LoginUser);
                customers.LoadNameAndIdByTicketID((int)Row["TicketID"]);
                string customerID = string.Empty;
                for (int i = 0; i < customers.Count; i++)
                {
                    // Per a skype conversation with Jesus their _Unknown Company needs to be excluded.
                    if (customers[i].OrganizationID != 624447)
                    {
                        customerID = customers[i].OrganizationID.ToString();
                        break;
                    }
                }
                writer.WriteElementString("CustomerID", customerID);
            }
            else if (_baseCollection.TableName == "TicketsView")
            {
                Organizations customers = new Organizations(_baseCollection.LoginUser);
                customers.LoadNameAndIdByTicketID((int)Row["TicketID"]);
                string customerID = string.Empty;

                writer.WriteStartElement("Customers");

                for (int i = 0; i < customers.Count; i++)
                {
                    customerID = customers[i].OrganizationID.ToString();
                    writer.WriteStartElement("Customer");
                    writer.WriteElementString("CustomerID", customerID);
                    writer.WriteElementString("CustomerName", customers[i].Name);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();

                ContactsView contacts = new ContactsView(_baseCollection.LoginUser);
                contacts.LoadNameAndIdByTicketID((int)Row["TicketID"]);
                string contactId = string.Empty;

                writer.WriteStartElement("Contacts");

                for (int i = 0; i < contacts.Count; i++)
                {
                    contactId = contacts[i].UserID.ToString();
                    writer.WriteStartElement("Contact");
                    writer.WriteElementString("ContactID", contactId);
                    writer.WriteElementString("ContactName", contacts[i].Name);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }

            if (includeCustomFields)
            {
                foreach (CustomField field in CustomFields)
                {
                    string s = "";
                    if (Row.Table.Columns.Contains(field.ApiFieldName))
                    {
                        if (Row[field.ApiFieldName] != DBNull.Value)
                        {
                            DataColumn column = Row.Table.Columns[field.ApiFieldName];
                            if (column.DataType == typeof(System.DateTime) || field.FieldType == CustomFieldType.Date)
                            {
                                DateTime fieldDateTime = DateTime.Parse(Row[field.ApiFieldName].ToString());
                                s = DateToLocal(fieldDateTime).ToString("g", _baseCollection.LoginUser.CultureInfo);
                            }
                            else if (column.DataType == typeof(System.Boolean) || field.FieldType == CustomFieldType.Boolean)
                            {
                                bool flag    = false;
                                int  flagInt = 0;

                                s = flag.ToString();

                                if (Boolean.TryParse(Row[field.ApiFieldName].ToString(), out flag))
                                {
                                    s = flag.ToString();
                                }
                                else if (int.TryParse(Row[field.ApiFieldName].ToString(), out flagInt))
                                {
                                    s = (flagInt > 0).ToString();
                                }
                            }
                            else
                            {
                                s = Row[field.ApiFieldName].ToString();
                            }
                        }
                    }
                    else
                    {
                        object value = field.GetValue(PrimaryKeyID);
                        if (value != null)
                        {
                            s = value.ToString();
                        }
                    }
                    string escape = SecurityElement.Escape(s).Replace(Convert.ToChar(0x0).ToString(), "").Replace(Convert.ToChar(0x1C).ToString(), "");
                    writer.WriteElementString(field.ApiFieldName, escape);
                }
            }

            if (tags != null)
            {
                writer.WriteStartElement("Tags");

                foreach (Tag tag in tags)
                {
                    writer.WriteStartElement("Tag");
                    writer.WriteElementString("Value", tag.Value);
                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
            }
        }