This commit is contained in:
parent c53a3d9e65
commit 2bc1c46ea2
2 changed files with 48 additions and 14 deletions

View File

@ -36,7 +36,7 @@ namespace AircraftPlantFileImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
return _source.Orders return _source.Orders
.Select(x => x.GetViewModel) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
@ -54,7 +54,7 @@ namespace AircraftPlantFileImplement.Implements
return _source.Orders return _source.Orders
.Where(x => x.Id.Equals(model.Id)) .Where(x => x.Id.Equals(model.Id))
.Select(x => x.GetViewModel) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
@ -70,9 +70,8 @@ namespace AircraftPlantFileImplement.Implements
return null; return null;
} }
return _source.Orders return GetViewModel(_source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)) .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
?.GetViewModel;
} }
/// <summary> /// <summary>
@ -92,7 +91,7 @@ namespace AircraftPlantFileImplement.Implements
_source.Orders.Add(newOrder); _source.Orders.Add(newOrder);
_source.SaveOrders(); _source.SaveOrders();
return newOrder.GetViewModel; return GetViewModel(newOrder);
} }
/// <summary> /// <summary>
@ -110,7 +109,7 @@ namespace AircraftPlantFileImplement.Implements
order.Update(model); order.Update(model);
_source.SaveOrders(); _source.SaveOrders();
return order.GetViewModel; return GetViewModel(order);
} }
/// <summary> /// <summary>
@ -125,9 +124,25 @@ namespace AircraftPlantFileImplement.Implements
{ {
_source.Orders.Remove(element); _source.Orders.Remove(element);
_source.SaveOrders(); _source.SaveOrders();
return element.GetViewModel; return GetViewModel(element);
} }
return null; return null;
} }
/// <summary>
/// Получение модели заказа
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var plane = _source.Planes.FirstOrDefault(x => x.Id == order.PlaneId);
if (plane != null)
{
viewModel.PlaneName = plane.PlaneName;
}
return viewModel;
}
} }
} }

View File

@ -38,7 +38,7 @@ namespace AircraftPlantListImplement.Implements
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
result.Add(order.GetViewModel); result.Add(GetViewModel(order));
} }
return result; return result;
} }
@ -60,7 +60,7 @@ namespace AircraftPlantListImplement.Implements
{ {
if (order.Id == model.Id) if (order.Id == model.Id)
{ {
result.Add(order.GetViewModel); result.Add(GetViewModel(order));
} }
} }
return result; return result;
@ -82,7 +82,7 @@ namespace AircraftPlantListImplement.Implements
{ {
if (model.Id.HasValue && order.Id == model.Id) if (model.Id.HasValue && order.Id == model.Id)
{ {
return order.GetViewModel; return GetViewModel(order);
} }
} }
return null; return null;
@ -111,7 +111,7 @@ namespace AircraftPlantListImplement.Implements
} }
_source.Orders.Add(newOrder); _source.Orders.Add(newOrder);
return newOrder.GetViewModel; return GetViewModel(newOrder);
} }
/// <summary> /// <summary>
@ -126,7 +126,7 @@ namespace AircraftPlantListImplement.Implements
if (order.Id == model.Id) if (order.Id == model.Id)
{ {
order.Update(model); order.Update(model);
return order.GetViewModel; return GetViewModel(order);
} }
} }
return null; return null;
@ -145,10 +145,29 @@ namespace AircraftPlantListImplement.Implements
{ {
var element = _source.Orders[i]; var element = _source.Orders[i];
_source.Orders.RemoveAt(i); _source.Orders.RemoveAt(i);
return element.GetViewModel; return GetViewModel(element);
} }
} }
return null; return null;
} }
/// <summary>
/// Получение модели заказа
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach (var sushi in _source.Planes)
{
if (sushi.Id == order.PlaneId)
{
viewModel.PlaneName = sushi.PlaneName;
break;
}
}
return viewModel;
}
} }
} }