Compare commits
2 Commits
049582dbc4
...
1e40ed2d43
Author | SHA1 | Date | |
---|---|---|---|
1e40ed2d43 | |||
19132c6645 |
@ -7,12 +7,12 @@ namespace ComputerShopContracts.ViewModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int UserId { get; }
|
||||
public int UserId { get; set; }
|
||||
|
||||
[DisplayName("Название комплектующей")]
|
||||
public string ComponentName { get; } = string.Empty;
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Стоимость")]
|
||||
public double Cost { get; }
|
||||
public double Cost { get; set; }
|
||||
}
|
||||
}
|
||||
|
65
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
65
ComputerShopDatabaseImplement/Models/Assembly.cs
Normal file
@ -0,0 +1,65 @@
|
||||
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()
|
||||
}
|
||||
}
|
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
22
ComputerShopDatabaseImplement/Models/AssemblyComponent.cs
Normal file
@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
}
|
50
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
50
ComputerShopDatabaseImplement/Models/Component.cs
Normal file
@ -0,0 +1,50 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
66
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
66
ComputerShopDatabaseImplement/Models/Product.cs
Normal file
@ -0,0 +1,66 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
22
ComputerShopDatabaseImplement/Models/ProductComponent.cs
Normal file
22
ComputerShopDatabaseImplement/Models/ProductComponent.cs
Normal file
@ -0,0 +1,22 @@
|
||||
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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user