public void SaveOrder(Order order, string Email) { Order existing = context.Customers .Include("Orders.OrderedMeals") .FirstOrDefault(c => c.EMail == Email) .Orders.FirstOrDefault(o => o.StartDate.Date == order.StartDate.Date); context.Customers .Include("Orders.OrderedMeals") .FirstOrDefault(c => c.EMail == Email) .Orders.Remove(existing); context.SaveChanges(); order.Id = 0; foreach (OrderedMeal oMeal in order.OrderedMeals) { oMeal.Id = 0; } context.Customers .Include("Orders.OrderedMeals") .FirstOrDefault(c => c.EMail == Email) .Orders.Add(order); context.SaveChanges(); }
public static void EnsurePopulated(IApplicationBuilder app) { AppOrderDbContext context = app.ApplicationServices.GetRequiredService <AppOrderDbContext>(); if (!context.Customers.Any()) { context.Customers.Add(new Customer() { EMail = "*****@*****.**", BirthDate = new DateTime(2000, 03, 24), Name = "Customer Jack", Address = "Lovensdijkstraat 61", PostalCode = "4000VM" }); context.SaveChanges(); } }