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}"); } }
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)); }
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}"); } }
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)); }
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); }
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()); }
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)); }
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)); }
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()); }
public static async Task <int> AddNewCFAsync(this AmoAccount acc, string cfName) { return(await acc.dataProvider.AddNewCFAsync(cfName, acc)); }
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)); }
public static async Task <int> GetCFIdAsync(this AmoAccount acc, string fieldName) { return(await acc.dataProvider.GetCFIdAsync(fieldName, acc)); }
public static async Task <int> GetTagIdAsync(this AmoAccount acc, string tagName) { return(await acc.dataProvider.GetTagIdAsync(tagName, acc)); }
public static async Task <List <City> > GetCityListAsync(this AmoAccount acc) { return(await acc.dataProvider.GetCityListAsync()); }
public static async Task AddNewCityAsync(this AmoAccount acc, string engCity, string rusCity) { await acc.dataProvider.AddNewCityAsync(engCity, rusCity); }
public static async Task <string> GetCityAsync(this AmoAccount acc, string input) { return(await acc.dataProvider.GetRusCityNameAsync(input)); }