PIbd-21 Lab3 Base Medvedkov_A_D_GiftShop #3

Closed
MaDerniszator wants to merge 3 commits from lab3 into lab2
2 changed files with 13 additions and 13 deletions
Showing only changes of commit 266e6aa1ac - Show all commits

View File

@ -19,7 +19,7 @@ namespace GiftShopDatabaseImplement.Implements
}
context.Orders.Remove(element);
context.SaveChanges();
return AcessDressesStorage(element.GetViewModel, context);
return AcessGiftsStorage(element.GetViewModel, context);
}
@ -30,7 +30,7 @@ namespace GiftShopDatabaseImplement.Implements
return null;
}
using var context = new GiftShopDatabase();
return AcessDressesStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context);
return AcessGiftsStorage(context.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel, context);
}
public List<OrderViewModel?> GetFilteredList(OrderSearchModel model)
@ -40,13 +40,13 @@ namespace GiftShopDatabaseImplement.Implements
return new();
}
using var context = new GiftShopDatabase();
return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
return context.Orders.Where(x => x.Id == model.Id).Select(x => AcessGiftsStorage(x.GetViewModel, context)).ToList();
}
public List<OrderViewModel?> GetFullList()
{
using var context = new GiftShopDatabase();
return context.Orders.Select(x => AcessDressesStorage(x.GetViewModel, context)).ToList();
return context.Orders.Select(x => AcessGiftsStorage(x.GetViewModel, context)).ToList();
}
@ -60,7 +60,7 @@ namespace GiftShopDatabaseImplement.Implements
using var context = new GiftShopDatabase();
context.Orders.Add(order);
context.SaveChanges();
return AcessDressesStorage(order.GetViewModel, context);
return AcessGiftsStorage(order.GetViewModel, context);
}
@ -76,22 +76,22 @@ namespace GiftShopDatabaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
return AcessDressesStorage(order.GetViewModel, context);
return AcessGiftsStorage(order.GetViewModel, context);
}
public static OrderViewModel? AcessDressesStorage(OrderViewModel? model, GiftShopDatabase context)
public static OrderViewModel? AcessGiftsStorage(OrderViewModel? model, GiftShopDatabase context)
Review

Cущности связаны, так что отдельный запрос для получения названия не требуется

Cущности связаны, так что отдельный запрос для получения названия не требуется
{
if (model == null)
{
return null;
}
var dress = context.Gifts.FirstOrDefault(x => x.Id == model.GiftId);
if (dress == null)
var gifts = context.Gifts.FirstOrDefault(x => x.Id == model.GiftId);
if (gifts == null)
{
return null;
}
model.GiftName = dress.GiftName;
model.GiftName = gifts.GiftName;
return model;
}

View File

@ -45,14 +45,14 @@ namespace GiftShopFileImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
return source.Orders.Where(x => x.Id == model.Id)
.Select(x => AcessDressesStorage(x.GetViewModel))
.Select(x => AcessGiftsStorage(x.GetViewModel))
.ToList();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => AcessDressesStorage(x.GetViewModel)).ToList();
return source.Orders.Select(x => AcessGiftsStorage(x.GetViewModel)).ToList();
}
@ -88,7 +88,7 @@ namespace GiftShopFileImplement.Implements
return order.GetViewModel;
}
public OrderViewModel AcessDressesStorage(OrderViewModel model)
public OrderViewModel AcessGiftsStorage(OrderViewModel model)
{
var component = source.Gifts.FirstOrDefault(x => x.Id == model.GiftId);
model.GiftName = component.GiftName;