// To protect from overposting attacks, please 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(ProductGuide).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductGuideExists(ProductGuide.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } var customer = await _context.Customers.FindAsync(id); if (customer == null) { return(NotFound()); } try { _context.Customers.Remove(customer); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log.) return(RedirectToAction("./Delete", new { id, saveChangesError = true })); } }
// To protect from overposting attacks, please 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.Products.Add(Product); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } ProductGuide = await _context.ProductGuides.FindAsync(id); if (ProductGuide != null) { _context.ProductGuides.Remove(ProductGuide); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { var emptyCustomer = new Customer(); if (await TryUpdateModelAsync <Customer>( emptyCustomer, "customer", // Prefix for form value. s => s.FirstMidName, s => s.LastName, s => s.SubscriptionDate)) { _context.Customers.Add(emptyCustomer); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync(int id) { var customerToUpdate = await _context.Customers.FindAsync(id); if (customerToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Customer>( customerToUpdate, "customer", c => c.FirstMidName, c => c.LastName, c => c.SubscriptionDate)) { await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } return(Page()); }