/// <summary> /// delete town from database /// </summary> /// <param name="deleteDtoModel"></param> /// <returns></returns> public async Task <bool> DeleteTownAsync(TownDeleteDtoModel deleteDtoModel) { var neededTown = await this.towns.All() .Include(x => x.UseFullCategories) .Include(x => x.Companies) .FirstOrDefaultAsync(x => x.Id == deleteDtoModel.TownId); if (neededTown == null) { return(false); } foreach (var item in neededTown.Companies.ToList()) { this.companyRepo.Delete(item); } foreach (var item in neededTown.UseFullCategories.ToList()) { this.townUseFullCategories.Delete(item); } this.towns.Delete(neededTown); await this.towns.SaveAsync(); return(true); }
public static TownDeleteDtoModel Map(TownDeleteViewModel viewModel) { var dtoModel = new TownDeleteDtoModel { TownId = viewModel.TownId }; return(dtoModel); }