Exemplo n.º 1
0
        public async Task <int> AddNewCFAsync(string fieldName, AmoAccount acc)
        {
            using var scope = scopeFactory.CreateScope();
            var db = scope.ServiceProvider.GetRequiredService <ICFRepo>();
            var cf = await db.GetCFByNameAsync(fieldName, acc.id);

            if (cf is not null)
            {
                return(cf.Id);
            }
            try
            {
                var leadRepo = acc.GetRepo <Lead>();
                var newCF    = leadRepo.AddField(fieldName).FirstOrDefault();
                await db.AddCFAsync(new CF()
                {
                    Id    = newCF.id,
                    Name  = newCF.name,
                    AmoId = acc.id
                });

                return(newCF.id);
            }
            catch (Exception e) { throw new InvalidOperationException($"Unable to add custom field {fieldName}: {e.Message}"); }
        }
Exemplo n.º 2
0
        public async Task <int> AddNewTagAsync(string tagName, AmoAccount account)
        {
            using var scope = scopeFactory.CreateScope();
            var db  = scope.ServiceProvider.GetRequiredService <ITagRepo>();
            var tag = await db.GetTagByName(tagName, account.id);

            if (tag is not null)
            {
                return(tag.Id);
            }
            try
            {
                var leadRepo = account.GetRepo <Lead>();
                var newTag   = leadRepo.AddTag(tagName).FirstOrDefault();
                await db.AddTag(new DBRepository.Tag()
                {
                    Id    = newTag.id,
                    Name  = newTag.name,
                    AmoId = account.id
                });

                return(newTag.id);
            }
            catch (Exception e) { throw new InvalidOperationException($"Unable to add tag {tagName}: {e.Message}"); }
        }