// 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.Order.Add(Order); await _context.SaveChangesAsync(); var order = _context.Order.Find(Order); var selection = Request.Form["selectedTables"]; foreach (var item in selection) { Order.OrderTables.Add(new OrderTable { OrderId = order.Id, Table = _context.Table.FirstOrDefault(t => t.Id.ToString() == item), Reservation = DateTime.Now }); } await _context.SaveChangesAsync(); 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() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(DietTag).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DietTagExists(DietTag.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(List <OrderItem> orderItems) { if (!ModelState.IsValid) { return(Page()); } Order.Items = await _context.OrderItem.Where(item => item.OrderId == Order.Id).ToListAsync(); _context.Attach(Order).State = EntityState.Modified; Order.Items = orderItems; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(Order.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() { if (!ModelState.IsValid) { return(Page()); } _context.DietTag.Add(DietTag); await _context.SaveChangesAsync(); 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[] dietselection) { //CHANGE: Removed Request.Form["dietselection"] and replaced with parameter in handler as seen above. (also parses string values to ints) if (!ModelState.IsValid) { return(Page()); } //Make sure the many-to-many is loaded into the model. Product.ProductTags = await _context.ProductTags.Where(pt => pt.ProductId == Product.Id).ToListAsync(); _context.Attach(Product).State = EntityState.Modified; //var dietTagsIds = Request.Form["dietselection"]; var dietTags = _context.DietTag.Where(tag => dietselection.Any(id => id == tag.Id)); var newTags = new List <ProductTag>(); foreach (var dietTag in dietTags) { var productTag = new ProductTag { Product = Product, ProductId = Product.Id, DietTag = dietTag, DietTagId = dietTag.Id }; newTags.Add(productTag); } //Update many-to-many trough the product. //This way there is no need to check if a productTag already exists. Product.ProductTags = newTags; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(Product.Id)) { return(NotFound()); } else { throw; } } 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")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } DietTag = await _context.DietTag.FindAsync(id); if (DietTag != null) { _context.DietTag.Remove(DietTag); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Table = await _context.Table.FindAsync(id); if (Table != null) { _context.Table.Remove(Table); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }