public string GetCustomFieldsSelect(ReferenceType refType, int?auxID, string refIDFieldName)
        {
            CustomFields = new CustomFields(LoginUser);
            int          orgID        = LoginUser.OrganizationID;
            Organization organization = Organizations.GetOrganization(LoginUser, LoginUser.OrganizationID);

            if (organization != null && organization.ParentID != 1)
            {
                orgID = (int)organization.ParentID;
            }
            _customFields.LoadByReferenceType(orgID, refType, auxID);
            return(GetCustomFieldsSelect(CustomFields, refIDFieldName));
        }
        public static string GetProductFamiliesRightsClause(LoginUser loginUser)
        {
            StringBuilder result = new StringBuilder();

            User user = Users.GetUser(loginUser, loginUser.UserID);

            if ((ProductFamiliesRightType)user.ProductFamiliesRights != ProductFamiliesRightType.AllFamilies)
            {
                Organization organization = Organizations.GetOrganization(loginUser, loginUser.OrganizationID);
                if (organization.UseProductFamilies)
                {
                    result.Append(" AND p.ProductFamilyID IN (SELECT ProductFamilyID FROM UserRightsProductFamilies WHERE UserID = @userID)");
                }
            }
            return(result.ToString());
        }
        public void RemoveCustomer(int organizationID, int productID)
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.CommandText = "DELETE FROM OrganizationProducts WHERE (ProductID = @ProductID) AND (OrganizationID = @OrganizationID)";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@OrganizationID", organizationID);
                command.Parameters.AddWithValue("@ProductID", productID);
                ExecuteNonQuery(command, "OrganizationProducts");
            }
            Organization org         = (Organization)Organizations.GetOrganization(LoginUser, organizationID);
            Product      product     = (Product)Products.GetProduct(LoginUser, productID);
            string       description = "Removed '" + product.Name + "' from the customer " + org.Name;

            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Products, productID, description);
            ActionLogs.AddActionLog(LoginUser, ActionLogType.Delete, ReferenceType.Organizations, organizationID, description);
        }
 public ContactsViewItem FindByEmail(string email, string organizationSalesForceID)
 {
     foreach (ContactsViewItem contactsViewItem in this)
     {
         string contactsViewItemOrganizationSalesForceID = Organizations.GetOrganization(this.LoginUser, contactsViewItem.OrganizationID).CRMLinkID;
         if (contactsViewItemOrganizationSalesForceID != null)
         {
             if (contactsViewItem.Email.Trim().ToLower() == email.Trim().ToLower())
             {
                 if (contactsViewItemOrganizationSalesForceID == organizationSalesForceID)
                 {
                     return(contactsViewItem);
                 }
             }
         }
     }
     return(null);
 }
        public static int GetAttemptCount(LoginUser loginUser, int userID, int minutes)
        {
            using (SqlCommand command = new SqlCommand())
            {
                DateTime dateCreated = DateTime.UtcNow.AddMinutes(-minutes);
                command.CommandText = "SELECT COUNT(*) FROM LoginAttempts WHERE DateCreated > @DateCreated AND UserID = @UserID AND Successful = 0";
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@UserID", userID);
                command.Parameters.AddWithValue("@DateCreated", dateCreated);

                Organizations organizations = new Organizations(loginUser);
                object        o             = organizations.ExecuteScalar(command);
                if (o == DBNull.Value)
                {
                    return(0);
                }
                else
                {
                    return((int)o);
                }
            }
        }
        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();
            }
        }
Exemple #7
0
        public WatercoolerAttachmentProxy GetProxy()
        {
            WatercoolerAttachmentProxy result = new WatercoolerAttachmentProxy();

            result.CreatorID    = this.CreatorID;
            result.RefType      = this.RefType;
            result.AttachmentID = this.AttachmentID;
            result.MessageID    = this.MessageID;

            result.DateCreated = DateTime.SpecifyKind(this.DateCreatedUtc, DateTimeKind.Utc);

            result.CreatorName = Users.GetUserFullName(BaseCollection.LoginUser, this.CreatorID);

            if (this.RefType == WaterCoolerAttachmentType.Group)
            {
                var group = Groups.GetGroup(BaseCollection.LoginUser, this.AttachmentID);
                if (group != null)
                {
                    result.GroupName = group.Name;
                }
                else
                {
                    return(null);
                }
            }

            if (this.RefType == WaterCoolerAttachmentType.Ticket)
            {
                var ticket = Tickets.GetTicketByNumber(BaseCollection.LoginUser, this.AttachmentID);
                if (ticket != null)
                {
                    result.TicketName = ticket.Name;
                }
                else
                {
                    return(null);
                }
            }

            if (this.RefType == WaterCoolerAttachmentType.Product)
            {
                var product = Products.GetProduct(BaseCollection.LoginUser, this.AttachmentID);
                if (product != null)
                {
                    result.ProductName = product.Name;
                }
                else
                {
                    return(null);
                }
            }

            if (this.RefType == WaterCoolerAttachmentType.Company)
            {
                var organization = Organizations.GetOrganization(BaseCollection.LoginUser, this.AttachmentID);
                if (organization != null)
                {
                    result.CompanyName = organization.Name;
                }
                else
                {
                    return(null);
                }
            }

            if (this.RefType == WaterCoolerAttachmentType.User)
            {
                var user = Users.GetUserFullName(BaseCollection.LoginUser, this.AttachmentID);
                if (user != null)
                {
                    result.UserName = user;
                }
                else
                {
                    return(null);
                }
            }

            if (this.RefType == WaterCoolerAttachmentType.Activities)
            {
                var activity = Notes.GetNote(BaseCollection.LoginUser, this.AttachmentID);
                if (activity != null)
                {
                    result.ActivityRefType = activity.RefType;
                    result.ActivityTitle   = activity.Title;
                    result.ActivityRefID   = activity.RefID;
                }
                else
                {
                    return(null);
                }
            }

            return(result);
        }
Exemple #8
0
        public static ChatRequest RequestChat(LoginUser loginUser, int organizationID, string firstName, string lastName, string email, string message, string ipAddress, int groupID = 0)
        {
            ChatClients clients = new ChatClients(loginUser);
            ChatClient  client  = clients.IsEmpty ? (new ChatClients(loginUser)).AddNewChatClient() : clients[0];

            client.OrganizationID = organizationID;
            client.FirstName      = firstName;
            client.LastName       = lastName;
            client.Email          = email;
            Users users = new Users(loginUser);

            if (!string.IsNullOrEmpty(email))
            {
                users.LoadByEmail(organizationID, email);

                try
                {
                    if (!users.IsEmpty)
                    {
                        client.LinkedUserID = users[0].UserID;
                        client.CompanyName  = Organizations.GetOrganization(loginUser, users[0].OrganizationID).Name;
                    }
                    else
                    {
                        string       emailDomain = email.Substring(email.LastIndexOf('@') + 1).Trim();
                        Organization org         = Organization.GetCompanyByDomain(organizationID, emailDomain, loginUser);
                        client.CompanyName = (org != null) ? org.Name : "";
                    }
                }
                catch (Exception)
                {
                    client.CompanyName = "";
                }
            }
            else
            {
                Organization org = Organization.GetCompanyByDomain(organizationID, string.Empty, loginUser, forceUnknown: true);
                client.CompanyName = (org != null) ? org.Name : "";
            }

            client.Collection.Save();


            Chat chat = (new Chats(loginUser)).AddNewChat();

            chat.InitiatorID    = client.ChatClientID;
            chat.InitiatorType  = ChatParticipantType.External;
            chat.OrganizationID = organizationID;
            chat.Collection.Save();

            Chats.JoinChat(loginUser, client.ChatClientID, ChatParticipantType.External, chat.ChatID, ipAddress);

            ChatRequest request = (new ChatRequests(loginUser)).AddNewChatRequest();

            request.RequestorID    = client.ChatClientID;
            request.RequestorType  = ChatParticipantType.External;
            request.OrganizationID = organizationID;
            request.ChatID         = chat.ChatID;
            request.Message        = message;
            request.IsAccepted     = false;
            request.RequestType    = ChatRequestType.External;
            request.GroupID        = groupID;
            request.Collection.Save();

            return(request);
        }
Exemple #9
0
        public static Organization Clone(LoginUser loginUser, int sourceOrganizationID, string cloneName)
        {
            Organization sOrg = Organizations.GetOrganization(loginUser, sourceOrganizationID);
            Organization dOrg = (new Organizations(loginUser)).AddNewOrganization();

            dOrg.CopyRowData(sOrg);
            dOrg.Name = cloneName;
            dOrg.Collection.Save();

            //** Groups **//
            Groups sGroups = new Groups(loginUser);

            sGroups.LoadByOrganizationID(sourceOrganizationID);

            Groups dGroups = new Groups(loginUser);

            foreach (Group sGroup in sGroups)
            {
                Group dGroup = dGroups.AddNewGroup();
                dGroup.CopyRowData(sGroup);
                dGroup.OrganizationID = dOrg.OrganizationID;
            }
            dGroups.Save();

            //** Users **//

            Users sUsers = new Users(loginUser);

            sUsers.LoadByOrganizationID(sourceOrganizationID, false);

            Users dUsers = new Users(loginUser);

            foreach (User sUser in sUsers)
            {
                User dUser = dUsers.AddNewUser();
                dUser.CopyRowData(sUser);
                dUser.OrganizationID = dOrg.OrganizationID;
                if (sUser.PrimaryGroupID != null)
                {
                    dUser.PrimaryGroupID = dGroups.FindByName(sGroups.FindByGroupID((int)sUser.PrimaryGroupID).Name).GroupID;
                }
            }
            dUsers.Save();


            //** Finish Organization w/ users and groups **//

            dOrg.DefaultPortalGroupID  = sOrg.DefaultPortalGroupID == null ? null : (int?)dGroups.FindByName(sGroups.FindByGroupID((int)sOrg.DefaultPortalGroupID).Name).GroupID;
            dOrg.PrimaryUserID         = sOrg.PrimaryUserID == null ? null : (int?)dUsers.FindByEmail(sUsers.FindByUserID((int)sOrg.PrimaryUserID).Email).UserID;
            dOrg.DefaultSupportUserID  = null;
            dOrg.DefaultSupportGroupID = null;
            dOrg.WebServiceID          = Guid.NewGuid();
            dOrg.SystemEmailID         = Guid.NewGuid();
            dOrg.PortalGuid            = Guid.NewGuid();
            dOrg.Collection.Save();

            //** Ticket Types **//

            TicketTypes sTicketTypes = new TicketTypes(loginUser);

            sTicketTypes.LoadByOrganizationID(sourceOrganizationID);

            TicketTypes dTicketTypes = new TicketTypes(loginUser);

            foreach (TicketType sTicketType in sTicketTypes)
            {
                TicketType dTicketType = dTicketTypes.AddNewTicketType();
                dTicketType.CopyRowData(sTicketType);
                dTicketType.OrganizationID = dOrg.OrganizationID;
            }
            dTicketTypes.Save();

            //** Ticket Severities **//

            TicketSeverities sSeverities = new TicketSeverities(loginUser);

            sSeverities.LoadByOrganizationID(sourceOrganizationID);

            TicketSeverities dSeverities = new TicketSeverities(loginUser);

            foreach (TicketSeverity sSeverity in sSeverities)
            {
                TicketSeverity dSeverity = dSeverities.AddNewTicketSeverity();
                dSeverity.CopyRowData(sSeverity);

                dSeverity.OrganizationID = dOrg.OrganizationID;
            }
            dSeverities.Save();

            //** Ticket Statuses **//

            TicketStatuses sStatuses = new TicketStatuses(loginUser);

            sStatuses.LoadByOrganizationID(sourceOrganizationID);

            TicketStatuses dStatuses = new TicketStatuses(loginUser);

            foreach (TicketStatus sStatus in sStatuses)
            {
                TicketType tempTT = sTicketTypes.FindByTicketTypeID(sStatus.TicketTypeID);
                if (tempTT == null)
                {
                    continue;
                }
                TicketStatus dStatus = dStatuses.AddNewTicketStatus();
                dStatus.CopyRowData(sStatus);
                dStatus.OrganizationID = dOrg.OrganizationID;
                dStatus.TicketTypeID   = dTicketTypes.FindByName(tempTT.Name).TicketTypeID;
            }
            dStatuses.Save();

            TicketNextStatuses sTicketNextStatuses = new TicketNextStatuses(loginUser);
            TicketNextStatuses dTicketNextStatuses = new TicketNextStatuses(loginUser);

            sTicketNextStatuses.LoadAll(sourceOrganizationID);

            foreach (TicketNextStatus sTicketNextStatus in sTicketNextStatuses)
            {
                TicketNextStatus dTicketNextStatus = dTicketNextStatuses.AddNewTicketNextStatus();
                dTicketNextStatus.CopyRowData(sTicketNextStatus);
                TicketStatus tempTS = sStatuses.FindByTicketStatusID(sTicketNextStatus.CurrentStatusID);
                TicketType   tempTT = dTicketTypes.FindByName(sTicketTypes.FindByTicketTypeID(tempTS.TicketTypeID).Name);
                dTicketNextStatus.CurrentStatusID = dStatuses.FindByName(tempTS.Name, tempTT.TicketTypeID).TicketStatusID;
                tempTS = sStatuses.FindByTicketStatusID(sTicketNextStatus.CurrentStatusID);
                tempTT = dTicketTypes.FindByName(sTicketTypes.FindByTicketTypeID(tempTS.TicketTypeID).Name);
                dTicketNextStatus.NextStatusID = dStatuses.FindByName(tempTS.Name, tempTT.TicketTypeID).TicketStatusID;



                //WORKING HERE
            }

            TicketTemplates sTicketTemplates = new TicketTemplates(loginUser);
            TicketTemplates dTicketTemplates = new TicketTemplates(loginUser);

            sTicketTemplates.LoadByOrganization(sourceOrganizationID);

            foreach (TicketTemplate sTicketTemplate in sTicketTemplates)
            {
                TicketTemplate dTicketTemplate = dTicketTemplates.AddNewTicketTemplate();
                dTicketTemplate.CopyRowData(sTicketTemplate);
                dTicketTemplate.OrganizationID = dOrg.OrganizationID;
                dTicketTemplate.TicketTypeID   = dTicketTemplate.TicketTypeID != null ? (int?)dTicketTypes.FindByName(sTicketTypes.FindByTicketTypeID((int)sTicketTemplate.TicketTypeID).Name).TicketTypeID : null;
            }

            //** ActionTypes **//

            ActionTypes sActionTypes = new ActionTypes(loginUser);

            sActionTypes.LoadByOrganizationID(sourceOrganizationID);
            ActionTypes dActionTypes = new ActionTypes(loginUser);

            foreach (ActionType sActionType in sActionTypes)
            {
                ActionType dActionType = dActionTypes.AddNewActionType();
                dActionType.CopyRowData(sActionType);
                dActionType.OrganizationID = dOrg.OrganizationID;
            }
            dActionTypes.Save();


            //** Products **//

            Products sProducts = new Products(loginUser);
            Products dProducts = new Products(loginUser);

            sProducts.LoadByOrganizationID(sourceOrganizationID);

            foreach (Product sProduct in sProducts)
            {
                Product dProduct = dProducts.AddNewProduct();
                dProduct.CopyRowData(sProduct);
                dProduct.OrganizationID = dOrg.OrganizationID;
            }
            dProducts.Save();

            ProductVersionStatuses sProductVersionStatuses = new ProductVersionStatuses(loginUser);
            ProductVersionStatuses dProductVersionStatuses = new ProductVersionStatuses(loginUser);

            sProductVersionStatuses.LoadByOrganizationID(sourceOrganizationID);

            foreach (ProductVersionStatus sProductVersionStatus in sProductVersionStatuses)
            {
                ProductVersionStatus dProductVersionStatus = dProductVersionStatuses.AddNewProductVersionStatus();
                dProductVersionStatus.CopyRowData(sProductVersionStatus);
                dProductVersionStatus.OrganizationID = dOrg.OrganizationID;
            }

            dProductVersionStatuses.Save();

            ProductVersions sProductVersions = new ProductVersions(loginUser);
            ProductVersions dProductVersions = new ProductVersions(loginUser);

            sProductVersions.LoadAll(sourceOrganizationID);

            foreach (ProductVersion sProductVersion in sProductVersions)
            {
                ProductVersion dProductVersion = dProductVersions.AddNewProductVersion();
                dProductVersion.CopyRowData(sProductVersion);
                dProductVersion.ProductID = dProducts.FindByName(sProducts.FindByProductID(sProductVersion.ProductID).Name).ProductID;
            }
            dProductVersions.Save();

            PortalOptions sPortalOptions = new PortalOptions(loginUser);
            PortalOptions dPortalOptions = new PortalOptions(loginUser);

            sPortalOptions.LoadByOrganizationID(sourceOrganizationID);

            foreach (PortalOption sPortalOption in sPortalOptions)
            {
                PortalOption dPortalOption = dPortalOptions.AddNewPortalOption();
                dPortalOption.CopyRowData(sPortalOption);
                dPortalOption.OrganizationID = dOrg.OrganizationID;
                dPortalOption.RequestGroup   = sPortalOption.RequestGroup == null ? null : (int?)dGroups.FindByName(sGroups.FindByGroupID((int)sPortalOption.RequestGroup).Name).GroupID;
                dPortalOption.RequestType    = sPortalOption.RequestType == null ? null : (int?)dTicketTypes.FindByName(sTicketTypes.FindByTicketTypeID((int)sPortalOption.RequestType).Name).TicketTypeID;;
            }
            dPortalOptions.Save();


            return(dOrg);

            /*
             * Actions
             * Addresses
             * Assets
             * ChatSettings
             * ChatUserSettings
             * CrmLinkTable
             * CrmLinkFields
             * CustomFieldCategories
             * CustomFields
             * CustomValues
             * FacebookOptions
             * ForumCategories
             * ForumPermissions
             * ForumTickets
             * GroupUsers
             * Notes
             * OrganizationEmails
             * OrganizationProducts
             * Organizations
             * OrganizationSettings
             * OrganizationTickets
             * PhoneNumbers
             * PhoneQueue
             * PhoneTypes
             * PortalOptions
             * Reminders
             * Reports
             * SlaLevels
             * SlaTriggers
             * Subscriptions
             * Tags
             * TagLinks
             * Automation Stuff
             * TicketQueue
             * TicketRatings
             * TicketRelationShips
             * Users(Contacts)
             * WaterCooler
             * WikiArticles
             */
        }
 public Organization GetOrganization()
 {
     return(Organizations.GetOrganization(this, this.OrganizationID));
 }