diff --git a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs index 41fcc45..61dac62 100644 --- a/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarDatabaseImplement/Implements/OrderStorage.cs @@ -12,7 +12,9 @@ namespace SushiBarDatabaseImplement.Implements public OrderViewModel? Delete(OrderBindingModel model) { using var context = new SushiBarDatabase(); - var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + var element = context.Orders + .Include(x => x.Sushi) + .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { context.Orders.Remove(element); @@ -30,6 +32,7 @@ namespace SushiBarDatabaseImplement.Implements } using var context = new SushiBarDatabase(); return context.Orders + .Include(x => x.Sushi) .FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) ?.GetViewModel; } @@ -42,9 +45,10 @@ namespace SushiBarDatabaseImplement.Implements } using var context = new SushiBarDatabase(); return context.Orders - .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) - .ToList(); + .Include(x => x.Sushi) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); } public List GetFullList() { @@ -65,13 +69,18 @@ namespace SushiBarDatabaseImplement.Implements using var context = new SushiBarDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return newOrder.GetViewModel; + return context.Orders + .Include(x => x.Sushi) + .FirstOrDefault(x => x.Id == newOrder.Id) + ?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) { using var context = new SushiBarDatabase(); - var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + var order = context.Orders + .Include(x => x.Sushi) + .FirstOrDefault(x => x.Id == model.Id); if (order == null) { return null; diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs index 5e3bac7..9fc4709 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Order.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Order.cs @@ -21,7 +21,6 @@ namespace SushiBarDatabaseImplement.Models public DateTime? DateImplement { get; set; } public int Id { get; set; } public Sushi Sushi { get; set; } - public static Order? Create(OrderBindingModel? model) { if (model == null) diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 84da6c9..58f8313 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -9,7 +9,7 @@ namespace SushiBarDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); }