Ejemplo n.º 1
0
 public PagedList<Subscriber> GetMembers(Segment segment, SubscribeType status = SubscribeType.Subscribed, int page = 1, int pageSize = 500)
 {
     return GetMembers(segment.MailingListID, segment.ID, status, page, pageSize);
 }
Ejemplo n.º 2
0
        public void Save(Segment segment)
        {
            // do some validation
            foreach (SegmentCriteria criteria in segment.Criteria)
            {
                if (criteria.SegmentID != segment.ID && criteria.SegmentID != 0)
                {
                    throw new InvalidOperationException("Cannot save criteria that belong to another segment");
                }
            }

            if (segment.ID == 0)
            {
                // we are inserting a new segment
                segment.ID = Create(segment.MailingListID, segment.Name, segment.MatchType);

                // inserting criteria for the new segment as well
                foreach (SegmentCriteria criteria in segment.Criteria)
                {
                    String field = criteria.Field.ToString();
                    if (criteria.Field == SegmentCriteriaField.CustomField) field = criteria.CustomFieldID.Value.ToString();
                    AddCriteria(segment.MailingListID, segment.ID, field, criteria.Comparer, criteria.Value, criteria.DateFrom, criteria.DateTo);
                }
            }
            else
            {
                // or we are updating an existing segment
                Update(segment);

                // updating criteria for the existing segment as well
                // we will load the existing segment from the database to compare it with our modified segment
                Segment existing = FindByID(segment.MailingListID, segment.ID);

                List<int> existingCriteriaIDs = existing.Criteria.Select(x => x.ID).ToList();
                List<int> segmentCriteriaIDs = segment.Criteria.Where(x => x.ID != 0).Select(x => x.ID).ToList();

                // find with criteria where deleted
                foreach (int idToDelete in existingCriteriaIDs.Where(id => !segmentCriteriaIDs.Contains(id)))
                {
                    RemoveCriteria(segment.MailingListID, segment.ID, idToDelete);
                }

                // find which criteria where modified
                foreach (int idToUpdate in segmentCriteriaIDs.Where(id => existingCriteriaIDs.Contains(id)))
                {
                    SegmentCriteria criteria = segment.Criteria.Single(c => c.ID == idToUpdate);
                    UpdateCriteria(segment.MailingListID, segment.ID, criteria);
                }

                // find which criteria where added
                foreach (SegmentCriteria criteria in segment.Criteria.Where(x => x.ID == 0))
                {
                    String field = criteria.Field.ToString();
                    if (criteria.Field == SegmentCriteriaField.CustomField) field = criteria.CustomFieldID.Value.ToString();
                    AddCriteria(segment.MailingListID, segment.ID, field, criteria.Comparer, criteria.Value, criteria.DateFrom, criteria.DateTo);
                }
            }

            // reload segment to populate the object with all properties
            Segment reloaded = FindByID(segment.MailingListID, segment.ID);
            Utilities.CopyProperties<Segment>(reloaded, segment);
        }
Ejemplo n.º 3
0
 private void Update(Segment segment)
 {
     _Manager.MakeRequest(HttpMethod.POST, String.Format("/lists/{0}/segments/{1}/update", segment.MailingListID, segment.ID), new
     {
         Name = segment.Name,
         MatchType = segment.MatchType
     });
 }