diff --git a/Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs b/Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs index 9bf9ddd..01fbb99 100644 --- a/Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs +++ b/Course/BusinessLogic/BusinessLogic/ImplementerLogic.cs @@ -19,7 +19,7 @@ namespace BusinessLogic.BusinessLogic } public List? ReadList(ImplementerSearchModel? model) { - _logger.LogInformation("ReadList. Login:{Login}. Id:{Id}", model.Login, model.Id); + _logger.LogInformation("ReadList. Login:{Login}. Id:{Id}", model!.Login, model.Id); var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model); if (list == null) { diff --git a/Course/Contracts/BindingModels/ProductBindingModel.cs b/Course/Contracts/BindingModels/ProductBindingModel.cs index 57e6974..763719d 100644 --- a/Course/Contracts/BindingModels/ProductBindingModel.cs +++ b/Course/Contracts/BindingModels/ProductBindingModel.cs @@ -8,6 +8,6 @@ namespace Contracts.BindingModels public int UserId { get; set; } public string Name { get; set; } = string.Empty; public double Cost { get; set; } - public Dictionary ProductDetails { get; set; } = new(); + public Dictionary DetailProducts { get; set; } = new(); } } diff --git a/Course/DatabaseImplement/DatabaseImplement.csproj b/Course/DatabaseImplement/DatabaseImplement.csproj index 132c02c..3dbe418 100644 --- a/Course/DatabaseImplement/DatabaseImplement.csproj +++ b/Course/DatabaseImplement/DatabaseImplement.csproj @@ -6,4 +6,17 @@ enable + + + + + + + + + + + + + diff --git a/Course/DatabaseImplement/FactoryGoWorkDatabase.cs b/Course/DatabaseImplement/FactoryGoWorkDatabase.cs new file mode 100644 index 0000000..69716f4 --- /dev/null +++ b/Course/DatabaseImplement/FactoryGoWorkDatabase.cs @@ -0,0 +1,19 @@ +using DatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +namespace DatabaseImplement +{ + public class FactoryGoWorkDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=GoWorkDB;Username=postgres;Password=postgres"); + } + + public virtual DbSet Products { get; set; } + public virtual DbSet Details { get; set; } + public virtual DbSet DetailProducts { get; set; } + public virtual DbSet Productions { get; set; } + public virtual DbSet DetailProductions { get; set; } + public virtual DbSet Implementers { get; set; } + } +} diff --git a/Course/DatabaseImplement/Models/Detail.cs b/Course/DatabaseImplement/Models/Detail.cs new file mode 100644 index 0000000..f62d1ce --- /dev/null +++ b/Course/DatabaseImplement/Models/Detail.cs @@ -0,0 +1,59 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DatabaseImplement.Models +{ + public class Detail : IDetailModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public double Cost { get; set; } + [Required] + public int UserId { get; set; } + [ForeignKey("DetailId")] + public virtual List DetailProducts { get; set; } = new(); + public static Detail? Create(DetailBindingModel model) + { + if (model == null) + { + return null; + } + return new Detail + { + Id = model.Id, + Name = model.Name, + Cost = model.Cost, + UserId = model.UserId + }; + } + public static Detail Create(DetailViewModel model) + { + return new Detail + { + Id = model.Id, + Name = model.Name, + Cost = model.Cost, + UserId = model.UserId + }; + } + public void Update(DetailBindingModel model) + { + if (model == null) + return; + Name = model.Name; + Cost = model.Cost; + } + public DetailViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Cost = Cost, + UserId = UserId + }; + } +} diff --git a/Course/DatabaseImplement/Models/DetailProduct.cs b/Course/DatabaseImplement/Models/DetailProduct.cs new file mode 100644 index 0000000..0316b16 --- /dev/null +++ b/Course/DatabaseImplement/Models/DetailProduct.cs @@ -0,0 +1,17 @@ +using System.ComponentModel.DataAnnotations; + +namespace DatabaseImplement.Models +{ + public class DetailProduct + { + public int Id { get; set; } + [Required] + public int DetailId { get; set; } + [Required] + public int ProductId { get; set; } + [Required] + public int Count { get; set; } + public virtual Detail Detail { get; set; } = new(); + public virtual Product Product { get; set; } = new(); + } +} diff --git a/Course/DatabaseImplement/Models/DetailProduction.cs b/Course/DatabaseImplement/Models/DetailProduction.cs new file mode 100644 index 0000000..ccf5ca7 --- /dev/null +++ b/Course/DatabaseImplement/Models/DetailProduction.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + internal class DetailProduction + { + } +} diff --git a/Course/DatabaseImplement/Models/Implementer.cs b/Course/DatabaseImplement/Models/Implementer.cs new file mode 100644 index 0000000..905b347 --- /dev/null +++ b/Course/DatabaseImplement/Models/Implementer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + internal class Implementer + { + } +} diff --git a/Course/DatabaseImplement/Models/Product.cs b/Course/DatabaseImplement/Models/Product.cs new file mode 100644 index 0000000..b662c02 --- /dev/null +++ b/Course/DatabaseImplement/Models/Product.cs @@ -0,0 +1,77 @@ +using Contracts.BindingModels; +using Contracts.ViewModels; +using DataModels.Models; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DatabaseImplement.Models +{ + public class Product : IProductModel + { + public int Id { get; set; } + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public double Cost { get; set; } + [Required] + public int UserId { get; set; } + private Dictionary? _detailProducts = null; + [NotMapped] + public Dictionary DetailProducts + { + get + { + if (_detailProducts == null) + { + _detailProducts = Details.ToDictionary(recDP => recDP.DetailId, recDP => (recDP.Detail as IDetailModel, recDP.Count)); + } + return _detailProducts; + } + } + + [ForeignKey("ProductId")] + public virtual List Details { get; set; } = new(); + public static Product? Create(ProductBindingModel model) + { + if (model == null) + { + return null; + } + return new Product + { + Id = model.Id, + Name = model.Name, + Cost = model.Cost, + UserId = model.UserId, + Details = model.DetailProducts.Select(x => new DetailProduct + { + //Detail = + }).ToList() + }; + } + public static Product Create(ProductViewModel model) + { + return new Product + { + Id = model.Id, + Name = model.Name, + Cost = model.Cost, + UserId = model.UserId + }; + } + public void Update(ProductBindingModel model) + { + if (model == null) + return; + Name = model.Name; + Cost = model.Cost; + } + public ProductViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Cost = Cost, + UserId = UserId + }; + } +} diff --git a/Course/DatabaseImplement/Models/Production.cs b/Course/DatabaseImplement/Models/Production.cs new file mode 100644 index 0000000..547fe59 --- /dev/null +++ b/Course/DatabaseImplement/Models/Production.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + internal class Production + { + } +}