// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Shrine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShrineExists(Shrine.id)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Shrine = await _context.Shrine.FindAsync(id); if (Shrine != null) { _context.Shrine.Remove(Shrine); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } // translating checked boxes to medallion objects List <Medallion> medallions = new List <Medallion>(); foreach (int i in checkedBoxes) { medallions.Add(new Medallion { labelIdx = i }); } // setting the shrineID's of all the dependent objects to that of the shrine region.shrineId = shrine.id; element.shrineId = shrine.id; foreach (Medallion m in medallions) { m.shrineId = shrine.id; _context.Medallion.Add(m); } // setting the shrine properties to each dependent object shrine.region = region; shrine.element = element; shrine.medallions = medallions; // adding everything to the database _context.Shrine.Add(shrine); _context.Region.Add(region); _context.Element.Add(element); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }