SomeDatabase

This commit is contained in:
Sergey Kozyrev 2024-04-21 20:36:07 +04:00
parent 52914c9bd4
commit 009e128f55
10 changed files with 223 additions and 2 deletions

View File

@ -19,7 +19,7 @@ namespace BusinessLogic.BusinessLogic
}
public List<ImplementerViewModel>? 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)
{

View File

@ -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<int, (IDetailModel, int)> ProductDetails { get; set; } = new();
public Dictionary<int, (IDetailModel, int)> DetailProducts { get; set; } = new();
}
}

View File

@ -6,4 +6,17 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.22" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Contracts\Contracts.csproj" />
<ProjectReference Include="..\DataModels\DataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -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<Product> Products { get; set; }
public virtual DbSet<Detail> Details { get; set; }
public virtual DbSet<DetailProduct> DetailProducts { get; set; }
public virtual DbSet<Production> Productions { get; set; }
public virtual DbSet<DetailProduction> DetailProductions { get; set; }
public virtual DbSet<Implementer> Implementers { get; set; }
}
}

View File

@ -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<DetailProduct> 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
};
}
}

View File

@ -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();
}
}

View File

@ -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
{
}
}

View File

@ -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
{
}
}

View File

@ -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<int, (IDetailModel, int)>? _detailProducts = null;
[NotMapped]
public Dictionary<int, (IDetailModel, int)> 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<DetailProduct> 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
};
}
}

View File

@ -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
{
}
}