public async Task <IActionResult> OnPostAsync() { Category = await DataContext.HomeReviewFeatureCategories .Include(o => o.Features) .ThenInclude(o => o.HomeFeatures) .Include(o => o.Features) .ThenInclude(o => o.HomeFeatureChoices) .Include(o => o.Features) .ThenInclude(o => o.UserWeights) .FirstOrDefaultAsync(o => o.Id == Category.Id); if (Category is null) { return(NotFound()); } foreach (var feature in Category.Features) { feature.HomeFeatures.Clear(); feature.HomeFeatureChoices.Clear(); feature.UserWeights.Clear(); await DataContext.SaveChangesAsync(); } Category.Features.Clear(); await DataContext.SaveChangesAsync(); DataContext.Remove(Category); await DataContext.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id is not null) { Category = await DataContext.HomeReviewFeatureCategories.FindAsync(id); } if (Category is null) { return(NotFound()); } return(Page()); }
public IActionResult OnGet(int?id) { if (id is not null) { FeatureCategory = DataContext.HomeReviewFeatureCategories.Find(id); } if (FeatureCategory is null) { return(NotFound()); } return(Page()); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var existingRecord = await DataContext.HomeReviewFeatureCategories.FirstOrDefaultAsync(r => r.Title == Title); var sortOrder = await DataContext.HomeReviewFeatureCategories.MaxAsync(r => (int?)r.SortOrder) ?? -1; if (existingRecord is null) { existingRecord = new Data.Models.HomeReviewFeatureCategory { Title = Title, SortOrder = sortOrder + 1 }; DataContext.HomeReviewFeatureCategories.Add(existingRecord); await DataContext.SaveChangesAsync(); } return(RedirectToPage("./Index")); }