пашет пашет
This commit is contained in:
parent
9be26628db
commit
e56dbb7f4b
@ -28,6 +28,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
{
|
{
|
||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение полного списка
|
/// Получение полного списка
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -41,6 +42,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение фильтрованного списка
|
/// Получение фильтрованного списка
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -63,6 +65,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение элемента
|
/// Получение элемента
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -84,6 +87,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление элемента
|
/// Добавление элемента
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -109,6 +113,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
_source.Orders.Add(newOrder);
|
_source.Orders.Add(newOrder);
|
||||||
return GetViewModel(newOrder);
|
return GetViewModel(newOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Редактирование элемента
|
/// Редактирование элемента
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -126,6 +131,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление элемента
|
/// Удаление элемента
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -144,6 +150,7 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение модели заказа
|
/// Получение модели заказа
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -152,11 +159,11 @@ namespace AircraftPlantListImplement.Implements
|
|||||||
private OrderViewModel GetViewModel(Order order)
|
private OrderViewModel GetViewModel(Order order)
|
||||||
{
|
{
|
||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
foreach (var plane in _source.Planes)
|
foreach (var sushi in _source.Planes)
|
||||||
{
|
{
|
||||||
if (plane.Id == order.PlaneId)
|
if (sushi.Id == order.PlaneId)
|
||||||
{
|
{
|
||||||
viewModel.PlaneName = plane.PlaneName;
|
viewModel.PlaneName = sushi.PlaneName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,9 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
public List<ComponentViewModel> GetFullList()
|
public List<ComponentViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Components.Select(x => x.GetViewModel).ToList();
|
return context.Components
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
{
|
{
|
||||||
@ -24,8 +26,12 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
return context.Components
|
||||||
|
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
}
|
}
|
||||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
{
|
{
|
||||||
@ -33,9 +39,13 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Components.FirstOrDefault(x =>(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
return context.Components
|
||||||
model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) &&
|
||||||
|
x.ComponentName == model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
{
|
{
|
||||||
@ -44,6 +54,7 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
context.Components.Add(newComponent);
|
context.Components.Add(newComponent);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
@ -57,6 +68,7 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
component.Update(model);
|
component.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return component.GetViewModel;
|
return component.GetViewModel;
|
||||||
@ -65,13 +77,14 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
context.Components.Remove(element);
|
return null;
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
context.Components.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,7 +3,11 @@ using AircraftPlantContracts.SearchModels;
|
|||||||
using AircraftPlantContracts.StoragesContracts;
|
using AircraftPlantContracts.StoragesContracts;
|
||||||
using AircraftPlantContracts.ViewModels;
|
using AircraftPlantContracts.ViewModels;
|
||||||
using AircraftPlantDatabaseImplement.Models;
|
using AircraftPlantDatabaseImplement.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AircraftPlantDatabaseImplement.Implements
|
namespace AircraftPlantDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
@ -13,38 +17,32 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Plane)
|
.Select(x => GetViewModel(x))
|
||||||
.Select(x => x.GetViewModel)
|
.ToList();
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Plane)
|
.Where(x => x.Id.Equals(model.Id))
|
||||||
.Where(x => x.Id == model.Id)
|
.Select(x => GetViewModel(x))
|
||||||
.Select(x => x.GetViewModel)
|
.ToList();
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new AircraftPlantDatabase();
|
|
||||||
return context.Orders
|
|
||||||
.Include(x => x.Plane)
|
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
using var context = new AircraftPlantDatabase();
|
||||||
|
return GetViewModel(context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
|
||||||
|
}
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var newOrder = Order.Create(model);
|
var newOrder = Order.Create(model);
|
||||||
@ -52,15 +50,12 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders
|
return GetViewModel(newOrder);
|
||||||
.Include(x => x.Plane)
|
|
||||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
@ -69,29 +64,33 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return context.Orders
|
return GetViewModel(order);
|
||||||
.Include(x => x.Plane)
|
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
var deletedElement = context.Orders
|
|
||||||
.Include(x => x.Plane)
|
|
||||||
.FirstOrDefault(x => x.Id == model.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return deletedElement;
|
return GetViewModel(element);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
private static OrderViewModel GetViewModel(Order order)
|
||||||
|
{
|
||||||
|
using var context = new AircraftPlantDatabase();
|
||||||
|
var viewModel = order.GetViewModel;
|
||||||
|
var plane = context.Planes.FirstOrDefault(x => x.Id == order.PlaneId);
|
||||||
|
if (plane != null)
|
||||||
|
{
|
||||||
|
viewModel.PlaneName = plane.PlaneName;
|
||||||
|
}
|
||||||
|
return viewModel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -18,11 +18,11 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Planes
|
return context.Planes
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Components)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Component)
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
public List<PlaneViewModel> GetFilteredList(PlaneSearchModel model)
|
public List<PlaneViewModel> GetFilteredList(PlaneSearchModel model)
|
||||||
{
|
{
|
||||||
@ -30,31 +30,31 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Planes
|
return context.Planes
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Components)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Component)
|
||||||
.Where(x => x.PlaneName.Contains(model.PlaneName))
|
.Where(x => x.PlaneName.Contains(model.PlaneName))
|
||||||
.ToList()
|
.ToList()
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
public PlaneViewModel? GetElement(PlaneSearchModel model)
|
public PlaneViewModel? GetElement(PlaneSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.PlaneName) &&
|
if (string.IsNullOrEmpty(model.PlaneName) && !model.Id.HasValue)
|
||||||
!model.Id.HasValue)
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
return context.Planes
|
return context.Planes
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Components)
|
||||||
.ThenInclude(x => x.Component)
|
.ThenInclude(x => x.Component)
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PlaneName) &&
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PlaneName) &&
|
||||||
x.PlaneName == model.PlaneName) ||
|
x.PlaneName == model.PlaneName) ||
|
||||||
(model.Id.HasValue && x.Id ==
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
model.Id))
|
?.GetViewModel;
|
||||||
?.GetViewModel;
|
|
||||||
}
|
}
|
||||||
public PlaneViewModel? Insert(PlaneBindingModel model)
|
public PlaneViewModel? Insert(PlaneBindingModel model)
|
||||||
{
|
{
|
||||||
@ -64,6 +64,7 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.Planes.Add(newPlane);
|
context.Planes.Add(newPlane);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newPlane.GetViewModel;
|
return newPlane.GetViewModel;
|
||||||
@ -74,12 +75,12 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var plane = context.Planes.FirstOrDefault(rec =>
|
var plane = context.Planes.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
rec.Id == model.Id);
|
|
||||||
if (plane == null)
|
if (plane == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
plane.Update(model);
|
plane.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
plane.UpdateComponents(context, model);
|
plane.UpdateComponents(context, model);
|
||||||
@ -96,8 +97,8 @@ namespace AircraftPlantDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new AircraftPlantDatabase();
|
using var context = new AircraftPlantDatabase();
|
||||||
var element = context.Planes
|
var element = context.Planes
|
||||||
.Include(x => x.Components)
|
.Include(x => x.Components)
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Planes.Remove(element);
|
context.Planes.Remove(element);
|
||||||
|
@ -5,28 +5,29 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.Diagnostics.Contracts;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace AircraftPlantDatabaseImplement.Models
|
namespace AircraftPlantDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Component : IComponentModel
|
public class Component : IComponentModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string ComponentName { get; private set; } = string.Empty;
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double Cost { get; set; }
|
public double Cost { get; set; }
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
[ForeignKey("ComponentId")]
|
||||||
public virtual List<PlaneComponent> PlaneComponents { get; set; } = new();
|
public virtual List<PlaneComponent> PlaneComponents { get; set; } = new();
|
||||||
|
|
||||||
public static Component? Create(ComponentBindingModel model)
|
public static Component? Create(ComponentBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Component()
|
return new Component()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
@ -34,27 +35,25 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
Cost = model.Cost
|
Cost = model.Cost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component Create(ComponentViewModel model)
|
public static Component Create(ComponentViewModel model)
|
||||||
{
|
{
|
||||||
return new Component
|
return new Component()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ComponentName = model.ComponentName,
|
ComponentName = model.ComponentName,
|
||||||
Cost = model.Cost
|
Cost = model.Cost
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(ComponentBindingModel model)
|
public void Update(ComponentBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ComponentName = model.ComponentName;
|
ComponentName = model.ComponentName;
|
||||||
Cost = model.Cost;
|
Cost = model.Cost;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ComponentViewModel GetViewModel => new()
|
public ComponentViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
@ -2,40 +2,40 @@
|
|||||||
using AircraftPlantContracts.ViewModels;
|
using AircraftPlantContracts.ViewModels;
|
||||||
using AircraftPlantDataModels.Enums;
|
using AircraftPlantDataModels.Enums;
|
||||||
using AircraftPlantDataModels.Models;
|
using AircraftPlantDataModels.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AircraftPlantDatabaseImplement.Models
|
namespace AircraftPlantDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Сущность "Заказ"
|
||||||
|
/// </summary>
|
||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int PlaneId { get; set; }
|
public int PlaneId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public OrderStatus Status { get; set; }
|
public OrderStatus Status { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; set; }
|
public DateTime DateCreate { get; set; }
|
||||||
|
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
|
|
||||||
public virtual Plane Plane { get; set; }
|
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model)
|
public static Order? Create(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Order()
|
|
||||||
|
return new Order
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
PlaneId = model.PlaneId,
|
PlaneId = model.PlaneId,
|
||||||
@ -46,17 +46,16 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
DateImplement = model.DateImplement
|
DateImplement = model.DateImplement
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
@ -65,8 +64,7 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
DateCreate = DateCreate,
|
DateCreate = DateCreate,
|
||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement
|
||||||
PlaneName = Plane.PlaneName
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
using System;
|
using AircraftPlantContracts.BindingModels;
|
||||||
|
using AircraftPlantContracts.ViewModels;
|
||||||
|
using AircraftPlantDataModels.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AircraftPlantContracts.BindingModels;
|
|
||||||
using AircraftPlantContracts.ViewModels;
|
|
||||||
using AircraftPlantDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace AircraftPlantDatabaseImplement.Models
|
namespace AircraftPlantDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
@ -19,6 +19,7 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public double Price { get; set; }
|
public double Price { get; set; }
|
||||||
private Dictionary<int, (IComponentModel, int)>? _planeComponents = null;
|
private Dictionary<int, (IComponentModel, int)>? _planeComponents = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
public Dictionary<int, (IComponentModel, int)> PlaneComponents
|
public Dictionary<int, (IComponentModel, int)> PlaneComponents
|
||||||
{
|
{
|
||||||
@ -27,7 +28,7 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
if (_planeComponents == null)
|
if (_planeComponents == null)
|
||||||
{
|
{
|
||||||
_planeComponents = Components
|
_planeComponents = Components
|
||||||
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||||
}
|
}
|
||||||
return _planeComponents;
|
return _planeComponents;
|
||||||
}
|
}
|
||||||
@ -55,6 +56,7 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
PlaneName = model.PlaneName;
|
PlaneName = model.PlaneName;
|
||||||
Price = model.Price;
|
Price = model.Price;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaneViewModel GetViewModel => new()
|
public PlaneViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
@ -66,10 +68,11 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
var planeComponents = context.PlaneComponents.Where(rec => rec.PlaneId == model.Id).ToList();
|
var planeComponents = context.PlaneComponents.Where(rec => rec.PlaneId == model.Id).ToList();
|
||||||
if (planeComponents != null && planeComponents.Count > 0)
|
if (planeComponents != null && planeComponents.Count > 0)
|
||||||
{ // удалили те, которых нет в модели
|
{
|
||||||
|
// Удаление компонентов, которых нет в модели
|
||||||
context.PlaneComponents.RemoveRange(planeComponents.Where(rec => !model.PlaneComponents.ContainsKey(rec.ComponentId)));
|
context.PlaneComponents.RemoveRange(planeComponents.Where(rec => !model.PlaneComponents.ContainsKey(rec.ComponentId)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
// обновили количество у существующих записей
|
// Обновление количества у существующих записей
|
||||||
foreach (var updateComponent in planeComponents)
|
foreach (var updateComponent in planeComponents)
|
||||||
{
|
{
|
||||||
updateComponent.Count = model.PlaneComponents[updateComponent.ComponentId].Item2;
|
updateComponent.Count = model.PlaneComponents[updateComponent.ComponentId].Item2;
|
||||||
|
@ -12,19 +12,18 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AircraftPlantDatabaseImplement.Models
|
namespace AircraftPlantDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Сущность "Магазин"
|
||||||
|
/// </summary>
|
||||||
public class Shop : IShopModel
|
public class Shop : IShopModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string ShopName { get; set; } = string.Empty;
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Address { get; set; } = string.Empty;
|
public string Address { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateOpening { get; set; }
|
public DateTime DateOpening { get; set; }
|
||||||
|
|
||||||
private Dictionary<int, (IPlaneModel, int)>? _shopPlanes = null;
|
private Dictionary<int, (IPlaneModel, int)>? _shopPlanes = null;
|
||||||
|
|
||||||
[NotMapped]
|
[NotMapped]
|
||||||
@ -41,10 +40,8 @@ namespace AircraftPlantDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public int MaxPlanes { get; set; }
|
public int MaxPlanes { get; set; }
|
||||||
|
|
||||||
[ForeignKey("ShopId")]
|
[ForeignKey("ShopId")]
|
||||||
public List<ShopPlane> Planes { get; set; } = new();
|
public List<ShopPlane> Planes { get; set; } = new();
|
||||||
|
|
||||||
public static Shop Create(AircraftPlantDatabase context, ShopBindingModel model)
|
public static Shop Create(AircraftPlantDatabase context, ShopBindingModel model)
|
||||||
{
|
{
|
||||||
return new Shop
|
return new Shop
|
||||||
|
Loading…
Reference in New Issue
Block a user