33 Commits

Author SHA1 Message Date
bekodeg
6ca4695641 + 2024-05-01 12:39:37 +04:00
bekodeg
de8a64c509 + 2024-05-01 12:37:40 +04:00
bekodeg
c2c4759c68 сборки с продавцами 2024-05-01 12:37:07 +04:00
bekodeg
7f6c134c57 PurchaseStorage 2024-05-01 12:37:07 +04:00
fa4c708e1c comment, storekeeper, vendor + изменения в их поисковых моделях 2024-05-01 12:37:07 +04:00
bekodeg
fa4bf3e8d4 build storage 2024-05-01 12:36:39 +04:00
bekodeg
2ff2aeb812 OrderStorage 2024-05-01 12:36:39 +04:00
bekodeg
765b68f754 productStorage 2024-05-01 12:36:39 +04:00
bekodeg
2f7003d3b7 productStorage 2024-05-01 12:36:39 +04:00
bekodeg
0a6730a722 componentStorage 2024-05-01 12:36:39 +04:00
bekodeg
7bcfa7e0e0 op 2024-05-01 12:36:39 +04:00
060c5dc37f cleaning условия без условий 2024-05-01 12:36:17 +04:00
bekodeg
3e68f069ce пурчайз 2024-05-01 12:36:17 +04:00
bekodeg
9df5c5d358 + order 2024-05-01 12:36:17 +04:00
bekodeg
0fd8a7fd8f product mtm 2024-05-01 12:36:17 +04:00
ca6035d7a1 Purchase и связи 2024-05-01 12:36:17 +04:00
bekodeg
ed846686ce cyjdf c,jhrf 2024-05-01 12:35:49 +04:00
bekodeg
7f429638b5 Сборка и комменты 2024-05-01 12:35:49 +04:00
4733811487 ссылки у кладовщика и работника 2024-05-01 12:35:23 +04:00
9688e5eb1c Vendor 2024-05-01 12:35:23 +04:00
34ada3ab98 vendor я напишу 2024-05-01 12:34:59 +04:00
bekodeg
95b2759a12 + 2024-05-01 12:31:56 +04:00
bekodeg
070473b0d6 фиг знает 2024-05-01 12:31:56 +04:00
bekodeg
affb89bb59 + 2024-05-01 12:31:13 +04:00
bekodeg
56b6290c71 сборки с продавцами 2024-05-01 12:25:11 +04:00
bekodeg
96c186a590 PurchaseStorage 2024-05-01 11:55:41 +04:00
bekodeg
326b2b2b87 Merge branch 'BACKDEV-408' of https://git.is.ulstu.ru/bekodeg/ComputerHardwareStore_YouAreProgrammer into BACKDEV-408 2024-05-01 11:35:38 +04:00
bekodeg
09dcc021c8 build storage 2024-05-01 11:35:35 +04:00
e249402043 comment, storekeeper, vendor + изменения в их поисковых моделях 2024-05-01 11:14:29 +04:00
bekodeg
1ae74a6fdb OrderStorage 2024-05-01 11:04:41 +04:00
bekodeg
5337beeb65 productStorage 2024-04-30 21:00:26 +04:00
bekodeg
db1fdee078 productStorage 2024-04-30 20:42:42 +04:00
4719cf6c0f интерфейсы business для коммента и покупки + в модели поиска добавила поля id пользователей (ищем только из тех, что создавал сам пользователь) 2024-04-30 14:36:36 +04:00
29 changed files with 782 additions and 56 deletions

View File

@@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreContra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreBusinessLogic", "ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj", "{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -35,10 +35,6 @@ Global
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD}.Release|Any CPU.Build.0 = Release|Any CPU
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09A57BE9-A653-4AAD-9FB2-1F8974F294CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -92,9 +92,9 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
{
return;
}
if (string.IsNullOrEmpty(model.Date))
if (string.IsNullOrEmpty(model.Text))
{
throw new ArgumentNullException("Нет даты у комментария", nameof(model.Date));
throw new ArgumentNullException("Нет текста комментария", nameof(model.Text));
}
}
}

View File

@@ -92,10 +92,6 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
{
return;
}
if (model.DateCreate == null) // TODO чего блин, всмысле нет
{
throw new ArgumentNullException("Нет даты создания покупки", nameof(model.Date));
}
if (model.Cost <= 0)
{
throw new ArgumentNullException("Стоимость покупки должна быть больше 0", nameof(model.Cost));

View File

@@ -8,6 +8,7 @@ namespace ComputerHardwareStoreContracts.BindingModels
public int VendorId { get; set; }
public double Cost { get; set; }
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
}

View File

@@ -0,0 +1,15 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.ViewModels;
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
{
public interface IBuildLogic
{
List<BuildViewModel>? ReadList(BuildSearchModel? model);
BuildViewModel? ReadElement(BuildSearchModel model);
bool Create(BuildBindingModel model);
bool Update(BuildBindingModel model);
bool Delete(BuildBindingModel model);
}
}

View File

@@ -0,0 +1,15 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.ViewModels;
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
{
public interface ICommentLogic
{
List<CommentViewModel>? ReadList(CommentSearchModel? model);
CommentViewModel? ReadElement(CommentSearchModel model);
bool Create(CommentBindingModel model);
bool Update(CommentBindingModel model);
bool Delete(CommentBindingModel model);
}
}

View File

@@ -0,0 +1,15 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.ViewModels;
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
{
public interface IPurchaseLogic
{
List<PurchaseViewModel>? ReadList(PurchaseSearchModel? model);
PurchaseViewModel? ReadElement(PurchaseSearchModel model);
bool Create(PurchaseBindingModel model);
bool Update(PurchaseBindingModel model);
bool Delete(PurchaseBindingModel model);
}
}

View File

@@ -4,12 +4,12 @@ using ComputerHardwareStoreContracts.ViewModels;
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
{
public interface IStoreKeeperLogic
public interface IStoreKeeperLogic
{
List<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model);
StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model);
bool Create(StoreKeeperBindingModel model);
bool Update(StoreKeeperBindingModel model);
bool Delete(StoreKeeperBindingModel model);
}
List<StoreKeeperViewModel>? ReadList(StoreKeeperSearchModel? model);
StoreKeeperViewModel? ReadElement(StoreKeeperSearchModel model);
bool Create(StoreKeeperBindingModel model);
bool Update(StoreKeeperBindingModel model);
bool Delete(StoreKeeperBindingModel model);
}
}

View File

@@ -6,14 +6,6 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="BusinessLogicsContracts\IStoreKeeperLogic.cs" />
</ItemGroup>
<ItemGroup>
<None Include="BusinessLogicsContracts\IStoreKeeperLogic.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
</ItemGroup>

View File

@@ -3,6 +3,7 @@
public class BuildSearchModel
{
public int? Id { get; set; }
public int VendorId { get; set; }
public string? Name { get; set; }
}
}

View File

@@ -3,6 +3,5 @@
public class CommentSearchModel
{
public int? Id { get; set; }
public DateTime? Date { get; set; }
}
}

View File

@@ -4,5 +4,6 @@
{
public int? Id { get; set; }
public string? Name { get; set; }
public int? StoreKeeperId { get; set; }
}
}

View File

@@ -4,5 +4,7 @@
{
public int? Id { get; set; }
public string? Name { get; set; }
public int VendorId { get; set; }
public List<int>? Builds { get; set; }
}
}

View File

@@ -3,6 +3,7 @@
public class PurchaseSearchModel
{
public int? Id { get; set; }
public int? VendorId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}

View File

@@ -4,6 +4,5 @@
{
public int? Id { get; set; }
public string? Login { get; set; }
public string? Password { get; set; }
}
}

View File

@@ -10,11 +10,12 @@ namespace ComputerHardwareStoreContracts.ViewModels
public double Cost { get; set; }
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; }
public DateTime? DateImplement { get; set; }
public int VendorId { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; set; } = new();
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; set; } = new();
}
}

View File

@@ -5,6 +5,7 @@
int VendorId { get; }
double Cost { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds { get; }
public Dictionary<int, (IProductModel, int)> PurchaseProducts { get; }
}

View File

@@ -28,6 +28,7 @@ namespace ComputerHardwareStoreDatabaseImplement
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<ProductComponent> ProductComponents { set; get; }
public virtual DbSet<StoreKeeper> StoreKeepers { set; get; }
public virtual DbSet<Build> Builds { set; get; }
public virtual DbSet<Order> Orders { set; get; }
@@ -38,5 +39,6 @@ namespace ComputerHardwareStoreDatabaseImplement
public virtual DbSet<Purchase> Purchases { set; get; }
public virtual DbSet<PurchaseBuild> PurchaseBuilds { set; get; }
public virtual DbSet<PurchaseProduct> PurchaseProducts { set; get; }
public virtual DbSet<Vendor> Vendors { set; get; }
}
}

View File

@@ -0,0 +1,117 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class BuildStorage : IBuildStorage
{
public List<BuildViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Builds
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Select(b => b.GetViewModel)
.ToList();
}
public List<BuildViewModel> GetFilteredList(BuildSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new ComputerHardwareStoreDBContext();
return context.Builds
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.VendorId )
.Where(b => b.Name.Contains(model.Name))
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Select(b => b.GetViewModel)
.ToList();
}
public BuildViewModel? GetElement(BuildSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Builds
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.VendorId)
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.FirstOrDefault(b =>
(!string.IsNullOrEmpty(model.Name) && b.Name == model.Name) ||
(model.Id.HasValue && b.Id == model.Id))?
.GetViewModel;
}
public BuildViewModel? Insert(BuildBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newBuild = Build.Create(context, model);
if (newBuild == null)
{
return null;
}
context.Builds.Add(newBuild);
context.SaveChanges();
return context.Builds
.Include(b => b.Vendor)
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.FirstOrDefault(p => p.Id == newBuild.Id)?
.GetViewModel;
}
public BuildViewModel? Update(BuildBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var build = context.Builds
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{
return null;
}
context.Update(model);
context.SaveChanges();
return build.GetViewModel;
}
public BuildViewModel? Delete(BuildBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var build = context.Builds
.Include(b => b.Comments)
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{
return null;
}
context.Builds.Remove(build);
context.SaveChanges();
return build.GetViewModel;
}
}
}

View File

@@ -0,0 +1,77 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class CommentStorage : ICommentStorage
{
public List<CommentViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Comments
.Select(x => x.GetViewModel)
.ToList();
}
public List<CommentViewModel> GetFilteredList(CommentSearchModel model)
{
using var context = new ComputerHardwareStoreDBContext();
return context.Comments
.Select(x => x.GetViewModel)
.ToList();
}
public CommentViewModel? GetElement(CommentSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Comments
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
public CommentViewModel? Insert(CommentBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newComment = Comment.Create(model);
if (newComment == null)
{
return null;
}
context.Comments.Add(newComment);
context.SaveChanges();
return newComment.GetViewModel;
}
public CommentViewModel? Update(CommentBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Comments.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return element.GetViewModel;
}
public CommentViewModel? Delete(CommentBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Comments.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Comments.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -12,7 +12,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
{
using var context = new ComputerHardwareStoreDBContext();
return context.Components
.Select(x => x.GetViewModel)
.Select(c => c.GetViewModel)
.ToList();
}
@@ -20,12 +20,12 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
{
if (string.IsNullOrEmpty(model.Name))
{
return new ();
return new();
}
using var context = new ComputerHardwareStoreDBContext();
return context.Components
.Where(x => x.Name.Contains(model.Name))
.Select(x => x.GetViewModel)
.Where(c => c.Name.Contains(model.Name))
.Select(c => c.GetViewModel)
.ToList();
}
@@ -37,10 +37,9 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
}
using var context = new ComputerHardwareStoreDBContext();
return context.Components
.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Name)
&& x.Name == model.Name)
|| (model.Id.HasValue && x.Id == model.Id))
.FirstOrDefault(c =>
(!string.IsNullOrEmpty(model.Name) && c .Name == model.Name) ||
(model.Id.HasValue && c.Id == model.Id))
?.GetViewModel;
}
@@ -59,27 +58,27 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
public ComponentViewModel? Update(ComponentBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
var element = context.Components.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
component.Update(model);
element.Update(model);
context.SaveChanges();
return component.GetViewModel;
return element.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
var element = context.Components.FirstOrDefault(c => c.Id == model.Id);
if (element == null)
{
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
return null;
}
return null;
context.Components.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
}
}

View File

@@ -0,0 +1,108 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class OrderStorage : IOrderStorage
{
public List<OrderViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Orders
.Include(o => o.Products)
.ThenInclude(o => o.Product)
.Select(o => o.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new ComputerHardwareStoreDBContext();
return context.Orders
.Include(o => o.Products)
.ThenInclude(o => o.Product)
.Where(o =>
(model.Id.HasValue && o.Id == model.Id) ||
((model.DateFrom.HasValue && model.DateTo.HasValue) &&
((model.DateFrom <= o.DateCreate && o.DateCreate <= model.DateTo) ||
(o.DateImplement.HasValue && o.DateCreate < model.DateFrom && model.DateFrom < o.DateImplement)))
)
.Select(o => o.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Orders
.Include(o => o.Products)
.ThenInclude(o => o.Product)
.FirstOrDefault(o => o.Id == model.Id)?
.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
using var transaction = context.Database.BeginTransaction();
try
{
var order = context.Orders
.Include(o => o.Products)
.ThenInclude(o => o.Product)
.FirstOrDefault(o => o.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
context.SaveChanges();
transaction.Commit();
return order.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Orders
.Include(o => o.Products)
.ThenInclude(o => o.Product)
.FirstOrDefault(o => o.Id == model.Id);
if (element != null)
{
context.Orders.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -0,0 +1,102 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class ProductStorage : IProductStorage
{
public List<ProductViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Products
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.Select(p => p.GetViewModel)
.ToList();
}
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
using var context = new ComputerHardwareStoreDBContext();
return context.Products
.Where(p => p.Name.Contains(model.Name))
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.Select(p => p.GetViewModel)
.ToList();
}
public ProductViewModel? GetElement(ProductSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Products
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.FirstOrDefault(p =>
(!string.IsNullOrEmpty(model.Name) && p.Name == model.Name) ||
(model.Id.HasValue && p.Id == model.Id))?
.GetViewModel;
}
public ProductViewModel? Insert(ProductBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newProduct = Product.Create(context, model);
if (newProduct == null)
{
return null;
}
context.Products.Add(newProduct);
context.SaveChanges();
return context.Products
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.FirstOrDefault(p => p.Id == newProduct.Id)?
.GetViewModel;
}
public ProductViewModel? Update(ProductBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var product = context.Products
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.FirstOrDefault(p => p.Id == model.Id);
if (product == null)
{
return null;
}
context.Update(model);
context.SaveChanges();
return product.GetViewModel;
}
public ProductViewModel? Delete(ProductBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var product = context.Products
.Include(p => p.Components)
.ThenInclude(p => p.Component)
.FirstOrDefault(p => p.Id == model.Id);
if (product == null)
{
return null;
}
context.Products.Remove(product);
context.SaveChanges();
return product.GetViewModel;
}
}
}

View File

@@ -0,0 +1,117 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class PurchaseStorage : IPurchaseStorage
{
public List<PurchaseViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Purchases
.Include(p => p.Builds)
.ThenInclude(p => p.Build)
.Include(p => p.Products)
.ThenInclude(p => p.Product)
.Select(p => p.GetViewModel)
.ToList();
}
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{
using var context = new ComputerHardwareStoreDBContext();
return context.Purchases
.Include(p => p.Builds)
.ThenInclude(p => p.Build)
.Include(p => p.Products)
.ThenInclude(p => p.Product)
.Where(p =>
(model.Id.HasValue && p.Id == model.Id) ||
((model.DateFrom.HasValue && model.DateTo.HasValue) &&
((model.DateFrom <= p.DateCreate && p.DateCreate <= model.DateTo) ||
(p.DateImplement.HasValue && p.DateCreate < model.DateFrom && model.DateFrom < p.DateImplement)))
)
.Select(p => p.GetViewModel)
.ToList();
}
public PurchaseViewModel? GetElement(PurchaseSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Purchases
.Include(p => p.Builds)
.ThenInclude(p => p.Build)
.Include(p => p.Products)
.ThenInclude(p => p.Product)
.FirstOrDefault(p => p.Id == model.Id)?
.GetViewModel;
}
public PurchaseViewModel? Insert(PurchaseBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newPurchase = Purchase.Create(context, model);
if (newPurchase == null)
{
return null;
}
context.Purchases.Add(newPurchase);
context.SaveChanges();
return newPurchase.GetViewModel;
}
public PurchaseViewModel? Update(PurchaseBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
using var transaction = context.Database.BeginTransaction();
try
{
var purchase = context.Purchases
.Include(p => p.Builds)
.ThenInclude(p => p.Build)
.Include(p => p.Products)
.ThenInclude(p => p.Product)
.FirstOrDefault(p => p.Id == model.Id);
if (purchase == null)
{
return null;
}
purchase.Update(model);
context.SaveChanges();
transaction.Commit();
return purchase.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public PurchaseViewModel? Delete(PurchaseBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Purchases
.Include(p => p.Builds)
.ThenInclude(p => p.Build)
.Include(p => p.Products)
.ThenInclude(p => p.Product)
.FirstOrDefault(o => o.Id == model.Id);
if (element != null)
{
context.Purchases.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -0,0 +1,86 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class StoreKeeperStorage : IStoreKeeperStorage
{
public StoreKeeperViewModel? GetElement(StoreKeeperSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.StoreKeepers
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login)
&& x.Login == model.Login)
|| (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<StoreKeeperViewModel> GetFilteredList(StoreKeeperSearchModel model)
{
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new ComputerHardwareStoreDBContext();
return context.StoreKeepers
.Where(x => x.Login.Contains(model.Login))
.Select(x => x.GetViewModel)
.ToList();
}
public List<StoreKeeperViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.StoreKeepers
.Include(x => x.Components)
.Select(x => x.GetViewModel)
.ToList();
}
public StoreKeeperViewModel? Insert(StoreKeeperBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newStoreKeeper = StoreKeeper.Create(context, model);
if (newStoreKeeper == null)
{
return null;
}
context.StoreKeepers.Add(newStoreKeeper);
context.SaveChanges();
return newStoreKeeper.GetViewModel;
}
public StoreKeeperViewModel? Update(StoreKeeperBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.StoreKeepers.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return element.GetViewModel;
}
public StoreKeeperViewModel? Delete(StoreKeeperBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.StoreKeepers.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.StoreKeepers.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -0,0 +1,84 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDatabaseImplement.Models;
namespace ComputerHardwareStoreDatabaseImplement.Implements
{
public class VendorStorage : IVendorStorage
{
public VendorViewModel? GetElement(VendorSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.Id.HasValue)
{
return null;
}
using var context = new ComputerHardwareStoreDBContext();
return context.Vendors
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login)
&& x.Login == model.Login)
|| (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<VendorViewModel> GetFilteredList(VendorSearchModel model)
{
if (string.IsNullOrEmpty(model.Login))
{
return new();
}
using var context = new ComputerHardwareStoreDBContext();
return context.Vendors
.Where(x => x.Login.Contains(model.Login))
.Select(x => x.GetViewModel)
.ToList();
}
public List<VendorViewModel> GetFullList()
{
using var context = new ComputerHardwareStoreDBContext();
return context.Vendors
.Select(x => x.GetViewModel)
.ToList();
}
public VendorViewModel? Insert(VendorBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var newVendor = Vendor.Create(context, model);
if (newVendor == null)
{
return null;
}
context.Vendors.Add(newVendor);
context.SaveChanges();
return newVendor.GetViewModel;
}
public VendorViewModel? Update(VendorBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Vendors.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
element.Update(model);
context.SaveChanges();
return element.GetViewModel;
}
public VendorViewModel? Delete(VendorBindingModel model)
{
using var context = new ComputerHardwareStoreDBContext();
var element = context.Vendors.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Vendors.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@@ -1,11 +1,9 @@

using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDataModels.Models;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.InteropServices;
namespace ComputerHardwareStoreDatabaseImplement.Models
{
@@ -16,7 +14,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
public string Name { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
[NotMapped]
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
[NotMapped]
public Dictionary<int, (IComponentModel, int)> BuildComponents
@@ -77,7 +75,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Price = model.Price;
}
public BuildViewModel GetViewModel() => new()
public BuildViewModel GetViewModel => new()
{
Id = Id,
Name = Name,

View File

@@ -14,13 +14,13 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
[Required]
public double Cost { get; set; }
[Required]
public virtual StoreKeeper? StoreKeeper { get; set; }
public virtual StoreKeeper? StoreKeeperЗЛ { get; set; }
[NotMapped]
IStoreKeeperModel IComponentModel.StoreKeeper => throw new NotImplementedException();
public IStoreKeeperModel? StoreKeeper { get; set; }
[ForeignKey("ComponentId")]
public virtual List<ProductComponent> ProductComponents { get; set; } = new();
public static Component? Create(ComputerHardwareStoreDBContext context, ComponentBindingModel model)
public static Component? Create(ComponentBindingModel model)
{
if (model == null)
{
@@ -31,7 +31,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
StoreKeeper = context.StoreKeepers.First(x => x.Id == model.StoreKeeper.Id)
StoreKeeper = model.StoreKeeper
};
}
public void Update (ComponentBindingModel model)

View File

@@ -17,6 +17,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
public double Cost { get; set; }
[Required]
public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; } = null;
private Dictionary<int, (IBuildModel, int)>? _purchaseBuilds = null;
[NotMapped]
public Dictionary<int, (IBuildModel, int)> PurchaseBuilds