Пример #1
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}"); }
        }
Пример #2
0
        public async Task <DBRepository.Tag> GetTagAsync(int tagId, AmoAccount account)
        {
            using var scope = scopeFactory.CreateScope();
            var db = scope.ServiceProvider.GetRequiredService <ITagRepo>();

            return(await db.GetTagById(tagId, account.id));
        }
Пример #3
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}"); }
        }
Пример #4
0
        public async Task <CF> GetCFAsync(int fieldId, AmoAccount acc)
        {
            using var scope = scopeFactory.CreateScope();
            var db = scope.ServiceProvider.GetRequiredService <ICFRepo>();

            return(await db.GetCFByIdAsync(fieldId, acc.id));
        }
Пример #5
0
        public async Task <string> GetTagNameAsync(int tagId, AmoAccount account)
        {
            using var scope = scopeFactory.CreateScope();
            var db  = scope.ServiceProvider.GetRequiredService <ITagRepo>();
            var tag = await db.GetTagById(tagId, account.id);

            return(tag.Name);
        }
Пример #6
0
        public async Task <List <CustomField> > GetCFListAsync(AmoAccount acc)
        {
            using var scope = scopeFactory.CreateScope();
            var db   = scope.ServiceProvider.GetRequiredService <ICFRepo>();
            var list = await db.GetAllCFsAsync();

            return(list.Select(x => new CustomField()
            {
                id = x.Id, name = x.Name
            }).ToList());
        }
Пример #7
0
        public async Task <int> GetCFIdAsync(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);
            }
            return(await AddNewCFAsync(fieldName, acc));
        }
Пример #8
0
        public async Task <int> GetTagIdAsync(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);
            }
            return(await AddNewTagAsync(tagName, account));
        }
Пример #9
0
        public async Task <List <AmoRepo.Tag> > GetTagListAsync(AmoAccount account)
        {
            List <AmoRepo.Tag> result = new();

            using var scope = scopeFactory.CreateScope();
            var db   = scope.ServiceProvider.GetRequiredService <ITagRepo>();
            var tags = await db.GetAllTags();

            return(tags.Select(x => new AmoRepo.Tag()
            {
                id = x.Id, name = x.Name
            }).ToList());
        }
Пример #10
0
 public static async Task <int> AddNewCFAsync(this AmoAccount acc, string cfName)
 {
     return(await acc.dataProvider.AddNewCFAsync(cfName, acc));
 }
Пример #11
0
        public static async Task <Dictionary <string, int> > GetCFDictionaryAsync(this AmoAccount acc)
        {
            var list = await acc.dataProvider.GetCFListAsync(acc);

            return(list.ToDictionary(x => x.name, x => x.id));
        }
Пример #12
0
 public static async Task <int> GetCFIdAsync(this AmoAccount acc, string fieldName)
 {
     return(await acc.dataProvider.GetCFIdAsync(fieldName, acc));
 }
Пример #13
0
 public static async Task <int> GetTagIdAsync(this AmoAccount acc, string tagName)
 {
     return(await acc.dataProvider.GetTagIdAsync(tagName, acc));
 }
Пример #14
0
 public static async Task <List <City> > GetCityListAsync(this AmoAccount acc)
 {
     return(await acc.dataProvider.GetCityListAsync());
 }
Пример #15
0
 public static async Task AddNewCityAsync(this AmoAccount acc, string engCity, string rusCity)
 {
     await acc.dataProvider.AddNewCityAsync(engCity, rusCity);
 }
Пример #16
0
 public static async Task <string> GetCityAsync(this AmoAccount acc, string input)
 {
     return(await acc.dataProvider.GetRusCityNameAsync(input));
 }