public async Task CreateUseFullCategoryByNameAsync(string name, string imageAddress) { var towns = this.towns.All(); if (imageAddress == null) { imageAddress = GlobalConstants.ImageAddress; } UseFullCategory useFullCategory = new UseFullCategory() { Name = name, ImageAddress = imageAddress, }; foreach (var town in towns) { TownUseFullCategory townUseFullCategory = new TownUseFullCategory() { UseFullCategory = useFullCategory, Town = town, }; await this.townUseFullCategories.AddAsync(townUseFullCategory); } await this.useFullCategories.AddAsync(useFullCategory); await this.useFullCategories.SaveChangesAsync(); }
public async Task CreateTownByNameAsync(string name) { var allUseFullCategories = this.useFullCategories.All(); Town town = new Town { Name = name, }; foreach (var useFullCategory in allUseFullCategories) { TownUseFullCategory townUseFullCategory = new TownUseFullCategory() { UseFullCategory = useFullCategory, Town = town, }; await this.townUseFullCategories.AddAsync(townUseFullCategory); } await this.towns.AddAsync(town); await this.towns.SaveChangesAsync(); }
/// <summary> /// create new town, create townusefullcategories and add them all to database /// </summary> /// <param name="name"></param> /// <returns></returns> public async Task CreateTownByNameAsync(string name) { var allUseFullCategories = await this.useFullCategoryService.GetAlluseFullCategoriesAsync(); Town town = new Town { Name = name, }; foreach (var useFullCategory in allUseFullCategories) { TownUseFullCategory townUseFullCategory = new TownUseFullCategory() { UseFullCategory = useFullCategory, Town = town, }; await this.townUseFullCategories.InsertAsync(townUseFullCategory); } await this.towns.InsertAsync(town); await this.towns.SaveAsync(); }