/// <summary> /// delete category and townusefullcategories that are conected with it from database /// </summary> /// <param name="dtoModel"></param> /// <returns></returns> public async Task <bool> DeleteUseFullCategoryAsync(UseFullDeleteDtoModel dtoModel) { var modelToDelete = await this.useFullCategories.All() .Include(x => x.Towns) .Include(x => x.Companies) .FirstOrDefaultAsync(x => x.Id == dtoModel.UseFullCategoryId); if (modelToDelete == null) { return(true); } foreach (var item in modelToDelete.Companies.ToList()) { this.companyRepo.Delete(item); } foreach (var item in modelToDelete.Towns.ToList()) { this.townUseFullCategories.Delete(item); } this.useFullCategories.Delete(modelToDelete); await this.towns.SaveAsync(); return(false); }
public static UseFullDeleteDtoModel Map(UseFullDeleteInputViewModel viewModel) { var dtomodel = new UseFullDeleteDtoModel { UseFullCategoryId = viewModel.UseFullCategoryId }; return(dtomodel); }