public async Task <IActionResult> OnDeleteCategories(List <SIContributionCategory_Dto> categories) { try { for (int i = 0; i < categories.Count; i++) { SIContributionCategory toDelete = ContribCatRepo.WithDetails().First(x => x.Id == categories[i].Id); List <SIContribution> contribs = toDelete.SIContributions.ToList(); for (int j = 0; j < toDelete.SIContributions.Count; j++) { await ContribsRepo.DeleteAsync(contribs[j]); } await ContribCatRepo.DeleteAsync(toDelete); } return(new JsonResult(GetCategoriesDS())); } catch (Exception ex) { return(StatusCode(500)); } }
public async Task SeedAsync(DataSeedContext context) { bool isUpdate = false; var sISetup = SISetupRepo.WithDetails().FirstOrDefault(); isUpdate = sISetup != null; sISetup = !isUpdate ? new SISetup() { ContributionCategories = new List <SIContributionCategory>(), TenantId = context.TenantId } : null; if (!sISetup.ContributionCategories.Any(x => x.Title == "Employee")) { SIContributionCategory category = new SIContributionCategory(); category.Title = "Employee"; category.IsExpense = false; category.TenantId = context.TenantId; category.SIContributions = new List <SIContribution>() { new SIContribution() { Title = "Annuity", Value = 9, IsPercentage = true, TenantId = context.TenantId }, new SIContribution() { Title = "Unemployment Contribution", Value = 1, IsPercentage = true, TenantId = context.TenantId } }; sISetup.ContributionCategories.Add(category); } if (!sISetup.ContributionCategories.Any(x => x.Title == "Employer")) { SIContributionCategory category = new SIContributionCategory(); category.Title = "Employer"; category.IsExpense = true; category.TenantId = context.TenantId; category.SIContributions = new List <SIContribution>() { new SIContribution() { Title = "Annuity", Value = 9, IsPercentage = true, TenantId = context.TenantId }, new SIContribution() { Title = "Unemployment Contribution", Value = 1, IsPercentage = true, TenantId = context.TenantId }, new SIContribution() { Title = "Occupational Hazard", Value = 2, IsPercentage = true, TenantId = context.TenantId } }; sISetup.ContributionCategories.Add(category); } if (!isUpdate) { await SISetupRepo.InsertAsync(sISetup); } else { await SISetupRepo.UpdateAsync(sISetup); } }