public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(CategoryType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoryTypeExists(CategoryType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <bool> CheckAndSave() { if (!ModelState.IsValid) { var err = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); throw new Exception($"Model is invalid, ModelState has {err.Count} errors. Try turning the page off and on again."); } TempData.CorrectEmptyArrays <int>(); await _context.BrickCategories.UpdateFromSelectList (Brick, TempData[nameof(categorySelectionOrig)] as int[], CategorySelect); await _context.BrickToBrick.UpdateFromSelectList (Brick, TempData[nameof(childrenSelectOrig)] as int[], ChildrenSelect); await _context.BrickToBrick.UpdateFromSelectList (Brick, TempData[nameof(parentsSelectOrig)] as int[], ParentsSelect, Relationship.Reversed); TempData.Clear(); _context.Attach(Brick).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BrickExists(Brick.Id)) { return(false); } else { throw; } } return(true); }