// 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(Customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(Customer.CustomerId)) { 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() { ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "Name"); ViewData["DeliveryPartnerId"] = new SelectList(_context.DeliveryPartner, "DeliveryPartnerId", "Name"); ViewData["RestaurantId"] = new SelectList(_context.Restaurant, "RestaurantId", "Name"); if (!ModelState.IsValid) { return(Page()); } var restaurantId = Order.RestaurantId; TimeSpan orderTime = Order.Date.TimeOfDay; var restaurant = await _context.Restaurant.Where(x => x.RestaurantId == restaurantId).ToListAsync(); TimeSpan restaurantStartTime = restaurant[0].StartTime; TimeSpan restaurantEndTime = restaurant[0].EndTime; if ((orderTime < restaurantStartTime) || (orderTime > restaurantEndTime)) { ModelState.AddModelError("Order.Date", "The Order Time should be within Restaurant Start Time and End Time"); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(Order).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(Order.OrderId)) { 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()); } TimeSpan duration = Restaurant.EndTime.Subtract(Restaurant.StartTime); if (TimeSpan.Compare(duration, TimeSpan.Zero) <= 0) { ModelState.AddModelError("Restaurant.EndTime", "The Restaurant End Time can not be less or equal to than Start Time"); } if (!ModelState.IsValid) { return(Page()); } _context.Attach(Restaurant).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RestaurantExists(Restaurant.RestaurantId)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }