Compare commits
No commits in common. "72ff843aff403c01cbc03300b3cf1e23584dfd20" and "8430c05951fc6c063dcc334b64816528174233a8" have entirely different histories.
72ff843aff
...
8430c05951
@ -13,7 +13,7 @@ namespace ComputerShopContracts.BindingModels
|
|||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; set; }
|
||||||
|
|
||||||
public int? AssemblyId { get; set; }
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
public DateTime DateMake { get; set; } = DateTime.Now;
|
public DateTime DateMake { get; set; } = DateTime.Now;
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
public int UserId { get; set; }
|
public int UserId { get; }
|
||||||
|
|
||||||
[DisplayName("Название комплектующей")]
|
[DisplayName("Название комплектующей")]
|
||||||
public string ComponentName { get; set; } = string.Empty;
|
public string ComponentName { get; } = string.Empty;
|
||||||
|
|
||||||
[DisplayName("Стоимость")]
|
[DisplayName("Стоимость")]
|
||||||
public double Cost { get; set; }
|
public double Cost { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ namespace ComputerShopContracts.ViewModels
|
|||||||
public string UserLogin { get; set; } = string.Empty;
|
public string UserLogin { get; set; } = string.Empty;
|
||||||
|
|
||||||
//id сборки
|
//id сборки
|
||||||
public int? AssemblyId { get; set; }
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
//!!!МБ НАДО БУДЕТ ПРИВЯЗЫВАТЬ НАЗВАНИЕ СБОРКИ И Т.Д. ДЛЯ ОТЧЁТОВ
|
//!!!МБ НАДО БУДЕТ ПРИВЯЗЫВАТЬ НАЗВАНИЕ СБОРКИ И Т.Д. ДЛЯ ОТЧЁТОВ
|
||||||
|
@ -17,7 +17,7 @@ namespace ComputerShopDataModels.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// ID сборки
|
/// ID сборки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int? AssemblyId { get; }
|
int AssemblyId { get; }
|
||||||
|
|
||||||
Dictionary<int, IOrderModel> RequestOrders { get; }
|
Dictionary<int, IOrderModel> RequestOrders { get; }
|
||||||
|
|
||||||
|
@ -17,23 +17,12 @@ namespace ComputerShopDatabaseImplement
|
|||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||||
}
|
}
|
||||||
public virtual DbSet<User> Users { get; set; }
|
|
||||||
|
|
||||||
public virtual DbSet<Component> Components { get; set; }
|
|
||||||
|
|
||||||
public virtual DbSet<Assembly> Assemblies { get; set; }
|
|
||||||
|
|
||||||
public virtual DbSet<AssemblyComponent> AssemblyComponents { get; set; }
|
|
||||||
|
|
||||||
public virtual DbSet<Product> Products { get; set; }
|
|
||||||
|
|
||||||
public virtual DbSet<ProductComponent> ProductComponents { get; set; }
|
|
||||||
|
|
||||||
|
|
||||||
public virtual DbSet<Order> Orders { get; set; }
|
public virtual DbSet<Order> Orders { get; set; }
|
||||||
public virtual DbSet<Request> Requests { get; set; }
|
public virtual DbSet<Request> Requests { get; set; }
|
||||||
public virtual DbSet<Shipment> Shipments { get; set; }
|
public virtual DbSet<Shipment> Shipments { get; set; }
|
||||||
public virtual DbSet<ShipmentOrder> ShipmentOrders { get; set; }
|
public virtual DbSet<ShipmentOrder> ShipmentOrders { get; set; }
|
||||||
public virtual DbSet<RequestOrder> RequestOrders { get; set; }
|
public virtual DbSet<RequestOrder> RequestOrders { get; set; }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
|
||||||
using ComputerShopDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Assembly : IAssemblyModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int UserId { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string AssemblyName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public double Cost { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string Category { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
|
||||||
public virtual List<AssemblyComponent> Components { get; set; } = new();
|
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _assemblyComponents;
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public Dictionary<int, (IComponentModel, int)> AssemblyComponents
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_assemblyComponents == null)
|
|
||||||
{
|
|
||||||
_assemblyComponents = Components.ToDictionary(
|
|
||||||
AsmComp => AsmComp.ComponentId,
|
|
||||||
AsmComp => (AsmComp.Component as IComponentModel, AsmComp.Count)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _assemblyComponents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Assembly Create(ComputerShopDatabase Context, AssemblyBindingModel Model)
|
|
||||||
{
|
|
||||||
return new()
|
|
||||||
{
|
|
||||||
Id = Model.Id,
|
|
||||||
UserId = Model.UserId,
|
|
||||||
AssemblyName = Model.AssemblyName,
|
|
||||||
Cost = Model.Cost,
|
|
||||||
Category = Model.Category,
|
|
||||||
Components = Model.AssemblyComponents.Select(x => new AssemblyComponent
|
|
||||||
{
|
|
||||||
Component = Context.Components.First(y => y.Id == x.Key),
|
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Update(), ViewModel, UpdateComponents()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class AssemblyComponent
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int AssemblyId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int ComponentId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
|
|
||||||
public virtual Assembly Assembly { get; set; } = new();
|
|
||||||
|
|
||||||
public virtual Component Component { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
|
||||||
using ComputerShopContracts.ViewModels;
|
|
||||||
using ComputerShopDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Component : IComponentModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int UserId { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string ComponentName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public double Cost { get; private set; }
|
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
|
||||||
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } = new();
|
|
||||||
|
|
||||||
public static Component Create(ComponentBindingModel Model)
|
|
||||||
{
|
|
||||||
return new()
|
|
||||||
{
|
|
||||||
Id = Model.Id,
|
|
||||||
UserId = Model.UserId,
|
|
||||||
ComponentName = Model.ComponentName,
|
|
||||||
Cost = Model.Cost,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(ComponentBindingModel Model)
|
|
||||||
{
|
|
||||||
ComponentName = Model.ComponentName;
|
|
||||||
Cost = Model.Cost;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ComponentViewModel ViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
UserId = UserId,
|
|
||||||
ComponentName = ComponentName,
|
|
||||||
Cost = Cost,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,7 +5,6 @@ using ComputerShopDataModels.Models;
|
|||||||
using System;
|
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.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -17,6 +16,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
//!!!ТУТ МБ СДЕЛАТЬ КАК FOREIGN KEY
|
||||||
[Required]
|
[Required]
|
||||||
public int UserId { get; private set; }
|
public int UserId { get; private set; }
|
||||||
|
|
||||||
@ -32,20 +32,13 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
//!!!мб не нужен
|
//!!!мб не нужен
|
||||||
public virtual User User { get; set; }
|
public virtual User User { get; set; }
|
||||||
|
|
||||||
//!!!ПРОВЕРМТЬ, ЧТО ПАРВИЛЬНЫЕ ВНЕШНИЕ КЛЮЧИ
|
|
||||||
|
|
||||||
[ForeignKey("OrderId")]
|
|
||||||
public virtual List<RequestOrder> RequestOrders { get; set; } = new();
|
|
||||||
|
|
||||||
[ForeignKey("OrderId")]
|
|
||||||
public virtual List<ShipmentOrder> ShipmentOrders { get; set; } = new();
|
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel model)
|
public static Order? Create(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
using var context = new ComputerShopDatabase();
|
||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
@ -63,7 +56,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
using var context = new ComputerShopDatabase();
|
using var context = new ComputerShopDatabase();
|
||||||
//!!!МБ НАДО БУДЕТ ОБНОВЛЯТЬ ПОЛЬЗОВАТЕЛЯ, НО ОН ПО СУТИ НЕ ДОЛЖЕН ОБНОВЛЯТЬСЯ ПОСЛЕ СОЗДАНИЯ
|
//!!!МБ НАДО БУДЕТ ОБНОВЛЯТЬ ПОЛЬЗОВАТЕЛЯ, НО ОН ПО СУТИ НЕ ДОЛЖЕН ОБНОВЯЛТЬСЯ ПОСЛЕ СОЗДАНИЯ
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
@ -1,66 +0,0 @@
|
|||||||
using ComputerShopContracts.BindingModels;
|
|
||||||
using ComputerShopDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class Product : IProductModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int UserId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public string ProductName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public double Cost { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Warranty { get; set; }
|
|
||||||
|
|
||||||
public int? ShipmentId { get; set; }
|
|
||||||
|
|
||||||
[ForeignKey("ComponentId")]
|
|
||||||
public virtual List<ProductComponent> Components { get; set; } = new();
|
|
||||||
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _productComponents;
|
|
||||||
|
|
||||||
[NotMapped]
|
|
||||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_productComponents == null)
|
|
||||||
{
|
|
||||||
_productComponents = Components.ToDictionary(
|
|
||||||
ProdComp => ProdComp.ComponentId,
|
|
||||||
ProdComp => (ProdComp.Component as IComponentModel, ProdComp.Count)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _productComponents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Product Create(ComputerShopDatabase Context, ProductBindingModel Model)
|
|
||||||
{
|
|
||||||
return new()
|
|
||||||
{
|
|
||||||
Id = Model.Id,
|
|
||||||
UserId = Model.UserId,
|
|
||||||
ProductName = Model.ProductName,
|
|
||||||
Cost = Model.Cost,
|
|
||||||
Warranty = Model.Warranty,
|
|
||||||
Components = Model.ProductComponents.Select(x => new ProductComponent
|
|
||||||
{
|
|
||||||
Component = Context.Components.First(y => y.Id == x.Key),
|
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList(),
|
|
||||||
ShipmentId = Model.ShipmentId,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace ComputerShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class ProductComponent
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int ProductId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int ComponentId { get; set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
|
|
||||||
public virtual Product Product { get; set; } = new();
|
|
||||||
|
|
||||||
public virtual Component Component { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ using System.Threading.Tasks;
|
|||||||
namespace ComputerShopDatabaseImplement.Models
|
namespace ComputerShopDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
//!!!ДОБАВИТЬ МЕТОД ПО ПРИВЯЗКЕ СБОРКИ
|
//!!!ДОБАВИТЬ МЕТОД ПО ПРИВЯЗКЕ СБОРКИ
|
||||||
//!!!МБ У Id сделать private set у ВСЕХ МОИХ МОДЕЛЕЙ
|
|
||||||
public class Request : IRequestModel
|
public class Request : IRequestModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -21,11 +20,9 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
|
|
||||||
public virtual User User { get; set; }
|
public virtual User User { get; set; }
|
||||||
|
|
||||||
public int? AssemblyId { get; set; }
|
public int AssemblyId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateMake { get; set; }
|
public DateTime DateMake { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string ClientFIO { get; set; } = string.Empty;
|
public string ClientFIO { get; set; } = string.Empty;
|
||||||
|
|
||||||
@ -39,17 +36,14 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
if (_requestOrders == null)
|
if (_requestOrders == null)
|
||||||
{
|
{
|
||||||
//!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК)
|
//!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК)
|
||||||
if (_requestOrders == null)
|
|
||||||
{
|
|
||||||
_requestOrders = Orders.ToDictionary(x => x.OrderId, x => (x.Order as IOrderModel));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return _requestOrders;
|
return _requestOrders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ForeignKey("RequestId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<RequestOrder> Orders { get; set; } = new();
|
public virtual List<RequestOrder> Orders { get; set; } = new();
|
||||||
|
|
||||||
public static Request Create(ComputerShopDatabase context, RequestBindingModel model)
|
public static Request Create(ComputerShopDatabase context, RequestBindingModel model)
|
||||||
|
@ -16,6 +16,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
//!!!ТУТ МБ СДЕЛАТЬ КАК FOREIGN KEY
|
||||||
[Required]
|
[Required]
|
||||||
public int UserId { get; private set; }
|
public int UserId { get; private set; }
|
||||||
|
|
||||||
@ -41,16 +42,17 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
if (_shipmentOrders == null)
|
if (_shipmentOrders == null)
|
||||||
{
|
{
|
||||||
//!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК)
|
//!!!ТУТ ПРОПИСАТЬ ЛОГИКУ (НЕ ЗНАЮ ПОКА, КАК)
|
||||||
_shipmentOrders = Orders.ToDictionary(x => x.OrderId, x => (x.Order as IOrderModel));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return _shipmentOrders;
|
return _shipmentOrders;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//!!!ПРОВЕРИТЬ, ЧТО ТУТ ПРАВИЛЬНО СДЕЛАНО (ЧТО НАЗВАНИЕ ПРАВИЛЬНОЕ У ВНЕШ. КЛЮЧА, ЧТО ПРАВИЛЬНЫЙ ТИП в <>)
|
//!!!ПРОВЕРИТЬ, ЧТО ТУТ ПРАВИЛЬНО СДЕЛАНО (ЧТО НАЗВАНИЕ ПРАВИЛЬНОЕ У ВНЕШ. КЛЮЧА, ЧТО ПРАВИЛЬНЫЙ ТИП в <>)
|
||||||
[ForeignKey("ShipmentId")]
|
[ForeignKey("OrderId")]
|
||||||
public virtual List<ShipmentOrder> Orders { get; set; } = new();
|
public virtual List<ShipmentOrder> Orders { get; set; } = new();
|
||||||
|
|
||||||
|
//!!!МБ ТУТ НАДО БУДЕТ ПРИСВАИВАТЬ ORDERS (но вряд ли, потому что по заданию заказы привязываются отдельно)
|
||||||
//!!!ПРОВЕРИТЬ, ЧТО ПРАВИЛЬНО ПРИСВАИВАЮ ЗНАЧЕНИЕ СПИСКУ ЗАКАЗОВ
|
//!!!ПРОВЕРИТЬ, ЧТО ПРАВИЛЬНО ПРИСВАИВАЮ ЗНАЧЕНИЕ СПИСКУ ЗАКАЗОВ
|
||||||
public static Shipment Create(ComputerShopDatabase context, ShipmentBindingModel model)
|
public static Shipment Create(ComputerShopDatabase context, ShipmentBindingModel model)
|
||||||
{
|
{
|
||||||
@ -94,6 +96,7 @@ namespace ComputerShopDatabaseImplement.Models
|
|||||||
//удаление тех заказов, которых нет в модели
|
//удаление тех заказов, которых нет в модели
|
||||||
if (shipmentOrders != null && shipmentOrders.Count > 0)
|
if (shipmentOrders != null && shipmentOrders.Count > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
//!!!ТУТ МБ НЕ x.OrderId, а x.ShipmentId, но не факт (вряд ли)
|
//!!!ТУТ МБ НЕ x.OrderId, а x.ShipmentId, но не факт (вряд ли)
|
||||||
context.ShipmentOrders.RemoveRange(shipmentOrders.Where(x => !model.ShipmentOrders.ContainsKey(x.OrderId)));
|
context.ShipmentOrders.RemoveRange(shipmentOrders.Where(x => !model.ShipmentOrders.ContainsKey(x.OrderId)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
Loading…
Reference in New Issue
Block a user