Ejemplo n.º 1
0
        public List <ChimpSegmentNameToken> GetMissingSegments(int userId, int listId)
        {
            var tokenList          = new List <ChimpSegmentNameToken>();
            var missingSegmentList = ChimpListSegmentRepository.GetMissingSegmentTokens(userId, listId);

            foreach (var missingSegment in missingSegmentList)
            {
                var nameList = missingSegment.ToSegmentNameTokenList();
                tokenList.AddRange(nameList);
            }
            return(tokenList);
        }
Ejemplo n.º 2
0
        public bool SaveListSegment(int listId, out string error)
        {
            error = string.Empty;

            CHIMP_UserLists chimpKeysEntity;

            if (!GetChimpKeys(listId, out chimpKeysEntity, out error))
            {
                return(false);
            }

            var mc = new MailChimpManager(chimpKeysEntity.ApiKey);

            var missingSegmentList = ChimpListSegmentRepository.GetMissingSegmentTokens(chimpKeysEntity.UserId, listId);

            foreach (var missingSegment in missingSegmentList)
            {
                var nameList = missingSegment.ToSegmentNameTokenList();
                foreach (var nameToken in nameList)
                {
                    try
                    {
                        var mcRes = mc.AddStaticSegment(chimpKeysEntity.Uid, nameToken.Name);
                        nameToken.Uid = mcRes.NewStaticSegmentID.ToString();

                        ChimpListSegmentRepository.Add(missingSegment.Token2SegmentEntity(nameToken));

                        if (!ChimpListSegmentRepository.UnitOfWork.CommitAndRefreshChanges(out error))
                        {
                            return(false);
                        }
                    }
                    catch (Exception mcException)
                    {
                        error = FormatError(mcException);
                        Logger.Error("Save list segments", mcException, listId, CommonEnums.LoggerObjectTypes.Mailchimp);
                        return(false);
                    }
                }
            }

            return(true);
        }