поменял слеганца
This commit is contained in:
parent
380740c36a
commit
2eb03ea5c1
@ -27,9 +27,9 @@ namespace FlowerShopDatabaseImplement.Models
|
|||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int FlowerId { get; private set; }
|
public int FlowerId { get; private set; }
|
||||||
public virtual Flower Flower { get; private set; }
|
public virtual Flower? Flower { get; private set; }
|
||||||
|
|
||||||
public static Order? Create(FlowerShopDataBase context,OrderBindingModel model)
|
public static Order? Create(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
@ -44,7 +44,7 @@ namespace FlowerShopDatabaseImplement.Models
|
|||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
FlowerId = model.FlowerId,
|
FlowerId = model.FlowerId,
|
||||||
Flower = context.Flowers.FirstOrDefault(x => x.Id == model.FlowerId)
|
//Flower = context.Flowers.FirstOrDefault(x => x.Id == model.FlowerId)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ namespace FlowerShopDatabaseImplement.Models
|
|||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
FlowerName = Flower.FlowerName,
|
FlowerName = Flower?.FlowerName ?? String.Empty ,
|
||||||
Id = Id,
|
Id = Id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new FlowerShopDataBase();
|
using var context = new FlowerShopDataBase();
|
||||||
return context.Orders.Include(x => x.Flower)
|
return context.Orders.Include(x => x.Flower)
|
||||||
.Select(x => AccessFlowerStorage(x.GetViewModel))
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
@ -31,7 +31,7 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
using var context = new FlowerShopDataBase();
|
using var context = new FlowerShopDataBase();
|
||||||
return context.Orders.Include(x => x.Flower)
|
return context.Orders.Include(x => x.Flower)
|
||||||
.Where(x => x.Id == model.Id)
|
.Where(x => x.Id == model.Id)
|
||||||
.Select(x => AccessFlowerStorage(x.GetViewModel))
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
@ -41,19 +41,19 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new FlowerShopDataBase();
|
using var context = new FlowerShopDataBase();
|
||||||
return AccessFlowerStorage(context.Orders.Include(x => x.Flower).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
return context.Orders.Include(x => x.Flower).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FlowerShopDataBase();
|
using var context = new FlowerShopDataBase();
|
||||||
var newOrder = Order.Create(context, model);
|
var newOrder = Order.Create( model);
|
||||||
if (newOrder == null)
|
if (newOrder == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessFlowerStorage(newOrder.GetViewModel);
|
return newOrder.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@ -65,36 +65,35 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessFlowerStorage(order.GetViewModel);
|
return order.GetViewModel;
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new FlowerShopDataBase();
|
using var context = new FlowerShopDataBase();
|
||||||
var element = context.Orders.Include(x => x.Flower).FirstOrDefault(rec => rec.Id ==
|
var element = context.Orders.Include(x => x.Flower).FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
model.Id);
|
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return AccessFlowerStorage(element.GetViewModel);
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OrderViewModel AccessFlowerStorage(OrderViewModel model)
|
//public static OrderViewModel AccessFlowerStorage(OrderViewModel model)
|
||||||
{
|
//{
|
||||||
if (model == null)
|
// if (model == null)
|
||||||
return null;
|
// return null;
|
||||||
using var context = new FlowerShopDataBase();
|
// using var context = new FlowerShopDataBase();
|
||||||
foreach (var flower in context.Flowers)
|
// foreach (var flower in context.Flowers)
|
||||||
{
|
// {
|
||||||
if (flower.Id == model.FlowerId)
|
// if (flower.Id == model.FlowerId)
|
||||||
{
|
// {
|
||||||
model.FlowerName = flower.FlowerName;
|
// model.FlowerName = flower.FlowerName;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return model;
|
// return model;
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user