// 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(Product).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(Product.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// 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(int?id, string[] selectedProducts) { if (id == null) { return(NotFound()); } var orderToUpdate = await _context.Order.Include(i => i.Customer).Include(i => i.OrderProducts).ThenInclude(i => i.Product).FirstOrDefaultAsync(s => s.ID == id); if (orderToUpdate == null) { return(NotFound()); } if (await TryUpdateModelAsync <Order>(orderToUpdate, "Order", i => i.Customer)) { UpdateOrderProducts(_context, selectedProducts, orderToUpdate); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care //este editata UpdateOrderProducts(_context, selectedProducts, orderToUpdate); PopulateAssignedProductData(_context, orderToUpdate); return(Page()); }
// 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(string[] selectedProducts) { var newOrder = new Order(); decimal tot = 0; if (selectedProducts != null) { newOrder.OrderProducts = new List <OrderProduct>(); foreach (var prod in selectedProducts) { string[] v = prod.Split('-'); var prodToAdd = new OrderProduct { ProductID = int.Parse(v[0]) }; newOrder.OrderProducts.Add(prodToAdd); tot += decimal.Parse(v[1]); } newOrder.OrderPrice = tot; } if (await TryUpdateModelAsync <Order>( newOrder, "Order", i => i.CustomerID)) { _context.Order.Add(newOrder); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); } PopulateAssignedProductData(_context, newOrder); return(Page()); }
// 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.Customer.Add(Customer); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Customer = await _context.Customer.FindAsync(id); if (Customer != null) { _context.Customer.Remove(Customer); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _context.Product.FindAsync(id); if (Product != null) { _context.Product.Remove(Product); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }