예제 #1
0
        /// <summary>
        /// Searches CRM by one of the 3 fields specified by searchType param. If no
        /// seachType if specified will default to email. Will only return results that
        /// match excatly the search string.
        /// </summary>
        /// <param name="searchString">string to search for</param>
        /// <param name="searchType">field to search for string in</param>
        /// <returns>IEnumberable of Type XrmV2.Contact</returns>
        public IEnumerable <Contact> SearchForContact(string searchString, SerachType searchType = SerachType.ByEmailOnly)
        {
            QueryExpression SearchQuery = new QueryExpression(Contact)
            {
                ColumnSet = DefaultColumnSet
            };

            switch (searchType)
            {
            case SerachType.ByEmailOnly:
                SearchQuery.Criteria.AddCondition(new ConditionExpression(Email, ConditionOperator.Equal, searchString));
                break;

            case SerachType.ByFirstNameOnly:
                SearchQuery.Criteria.AddCondition(new ConditionExpression(FirstName, ConditionOperator.Equal, searchString));
                break;

            case SerachType.ByLastNameOnly:
                SearchQuery.Criteria.AddCondition(new ConditionExpression(LastName, ConditionOperator.Equal, searchString));
                break;

            default:
                SearchQuery.Criteria.AddCondition(new ConditionExpression(Email, ConditionOperator.Equal, searchString));
                break;
            }

            return(XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(SearchQuery).Entities.Cast <Contact>());
        }
예제 #2
0
        public IEnumerable <Contact> SearchForContact(List <Guid> ListOfIds)
        {
            //QueryExpression SearchQuery = new QueryExpression(Contact) { ColumnSet = DefaultColumnSet };
            //ConditionExpression condition = new ConditionExpression(ContactGUID, ConditionOperator.In, ListOfIds);
            //SearchQuery.Criteria.AddCondition(condition);
            return(XrmConnection.GetCrmContext().ContactSet.Where(c => ListOfIds.Contains(c.Id)));

            // return XrmConnection.GetOrganizationService()
            //   .RetrieveMultiple(SearchQuery).Entities.Cast<Contact>();
        }
예제 #3
0
        public IEnumerable <Guid> GetDoNotMailList()
        {
            QueryExpression SearchQuery = new QueryExpression(Contact)
            {
                ColumnSet = new ColumnSet(ContactGUID)
            };
            ConditionExpression condition = new ConditionExpression(MarketingList, ConditionOperator.Equal, (int)MarketingLists.DoNotSend);

            SearchQuery.Criteria.AddCondition(condition);
            return(XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(SearchQuery).Entities.Cast <Contact>().Select(c => c.Id));
        }
예제 #4
0
        /// <summary>
        /// Will get all Contacts from CRM that have FREZZOR ID Numbers in them.
        /// </summary>
        /// <returns></returns>
        private IEnumerable <Contact> GetAllExigoContacts()
        {
            QueryExpression AllExigoContacts = new QueryExpression(Contact)
            {
                ColumnSet = DefaultColumnSet
            };
            ConditionExpression condition = new ConditionExpression(FrezzorID, ConditionOperator.NotNull);

            AllExigoContacts.Criteria.AddCondition(condition);

            return(XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(AllExigoContacts).Entities.Cast <Contact>());
        }
예제 #5
0
        public IEnumerable <Contact> GetAllBirthDayEqOne()
        {
            QueryExpression SearchQuery = new QueryExpression(Contact)
            {
                ColumnSet = DefaultColumnSet
            };
            ConditionExpression condition  = new ConditionExpression(DayOfBirth, ConditionOperator.Equal, 1);
            ConditionExpression condition2 = new ConditionExpression(MonthOfBirth, ConditionOperator.Equal, 1);

            SearchQuery.Criteria.AddCondition(condition);
            SearchQuery.Criteria.AddCondition(condition2);

            return(XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(SearchQuery).Entities.Cast <Contact>());
        }
예제 #6
0
        /// <summary>
        /// Searches CRM for contacts that match exactly First and Last Name
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <returns>IEnumberable of Type XrmV2.Contact</returns>
        public IEnumerable <Contact> SearchForContact(string firstName, string lastName)
        {
            QueryExpression SearchQuery = new QueryExpression(Contact)
            {
                ColumnSet = DefaultColumnSet
            };
            ConditionExpression condition  = new ConditionExpression(LastName, ConditionOperator.Equal, lastName);
            ConditionExpression condition2 = new ConditionExpression(FirstName, ConditionOperator.Equal, firstName);

            SearchQuery.Criteria.AddCondition(condition);
            SearchQuery.Criteria.AddCondition(condition2);

            return(XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(SearchQuery).Entities.Cast <Contact>());
        }
예제 #7
0
        public int GetLastIDNumber()
        {
            QueryExpression qExpr = new QueryExpression(Contact)
            {
                ColumnSet = new ColumnSet(FrezzorID)
            };
            OrderExpression     orderExpr = new OrderExpression(FrezzorID, OrderType.Descending);
            ConditionExpression condition = new ConditionExpression(FrezzorID, ConditionOperator.NotNull);

            // ConditionExpression condition2 = new ConditionExpression(EnrollerId, ConditionOperator.NotNull);
            qExpr.Criteria.AddCondition(condition);
            //qExpr.Criteria.AddCondition(condition2);
            qExpr.Orders.Add(orderExpr);
            qExpr.TopCount = 1;
            return((int)XrmConnection.GetOrganizationService()
                   .RetrieveMultiple(qExpr).Entities.Cast <Contact>().FirstOrDefault().new_FREZZORID);
        }
예제 #8
0
        public DateTime GetLastExigoModifedDate()
        {
            QueryExpression SearchQuery = new QueryExpression(Contact)
            {
                ColumnSet = DefaultColumnSet
            };
            OrderExpression     order     = new OrderExpression(FrezzorLastModDate, OrderType.Descending);
            ConditionExpression condition = new ConditionExpression(FrezzorID, ConditionOperator.NotNull);

            SearchQuery.Criteria.AddCondition(condition);
            SearchQuery.Orders.Add(order);
            SearchQuery.TopCount = 1;

            var d = XrmConnection.GetOrganizationService()
                    .RetrieveMultiple(SearchQuery).Entities.Cast <Contact>().FirstOrDefault().new_ExigoLastModifiedDate;

            return((DateTime)d);
        }
예제 #9
0
 public static FrezzorXCrm.XCrmContext GetCRMContext()
 {
     return(XrmConnection.GetCrmContext());
 }
예제 #10
0
 public Contact GetSingleContat(Guid id)
 {
     return(XrmConnection.GetOrganizationService()
            .Retrieve(Contact, id, DefaultColumnSet).ToEntity <Contact>());
 }