Исправление модели отображения заказа
This commit is contained in:
parent
1a41ad5ce3
commit
e962963589
@ -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,6 +45,7 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new SushiBarDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Sushi)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user