Исправление модели отображения заказа
This commit is contained in:
parent
1a41ad5ce3
commit
e962963589
@ -12,7 +12,9 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new SushiBarDatabase();
|
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)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
@ -30,6 +32,7 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
|
.Include(x => x.Sushi)
|
||||||
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
@ -42,6 +45,7 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
|
.Include(x => x.Sushi)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
@ -65,13 +69,18 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newOrder.GetViewModel;
|
return context.Orders
|
||||||
|
.Include(x => x.Sushi)
|
||||||
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new SushiBarDatabase();
|
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)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -21,7 +21,6 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public Sushi Sushi { get; set; }
|
public Sushi Sushi { get; set; }
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
@ -9,7 +9,7 @@ namespace SushiBarDatabaseImplement
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
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);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user