Создание слоя с базой данных и изменения предыдущих слоев
This commit is contained in:
parent
9e6dab9f5f
commit
a9b6277b55
@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProducts
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProductsBusinessLogic", "AccountingWarehouseProductsBusinessLogic\AccountingWarehouseProductsBusinessLogic.csproj", "{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProductsDatabaseImplement", "AccountingWarehouseProductsDatabaseImplement\AccountingWarehouseProductsDatabaseImplement.csproj", "{1063D739-0279-4F6A-BD7B-13E51EAA3410}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1063D739-0279-4F6A-BD7B-13E51EAA3410}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1063D739-0279-4F6A-BD7B-13E51EAA3410}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1063D739-0279-4F6A-BD7B-13E51EAA3410}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1063D739-0279-4F6A-BD7B-13E51EAA3410}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -11,6 +11,8 @@ namespace AccountingWarehouseProductsContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string StandName { get; set; }
|
||||
|
||||
public DateTime? DeliveryDate { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
@ -9,5 +9,7 @@ namespace AccountingWarehouseProductsContracts.SearchModels
|
||||
public class StandSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string StandName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -13,6 +14,9 @@ namespace AccountingWarehouseProductsContracts.ViewModels
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название поставки")]
|
||||
public string StandName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Дата поставки")]
|
||||
public DateTime? DeliveryDate { get; set; }
|
||||
|
||||
|
@ -8,12 +8,13 @@ namespace AccountingWarehouseProductsDataModels.Models
|
||||
{
|
||||
public interface IStandModel : IId
|
||||
{
|
||||
string StandName { get; }
|
||||
DateTime? DeliveryDate { get; }
|
||||
|
||||
int Count { get; }
|
||||
|
||||
int ProductId { get; }
|
||||
|
||||
int SupplierId { get; }
|
||||
int SupplierId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
using AccountingWarehouseProductsDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement
|
||||
{
|
||||
public class AccountingWarehouseProductsDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=.\SQLEXPRESS;Initial Catalog=AccountingWarehouseProductsDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public virtual DbSet<Supplier> Suppliers { get; set; }
|
||||
public virtual DbSet<Warehouse> Warehouses { get; set; }
|
||||
public virtual DbSet<Product> Products { get; set; }
|
||||
public virtual DbSet<Shipment> Shipments { get; set; }
|
||||
public virtual DbSet<Stand> Stands { get; set; }
|
||||
public virtual DbSet<Order> Orders { get; set; }
|
||||
public virtual DbSet<OrderProduct> OrderProducts { get; set; }
|
||||
public virtual DbSet<WarehouseProduct> WarehouseProducts { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AccountingWarehouseProductsContracts\AccountingWarehouseProductsContracts.csproj" />
|
||||
<ProjectReference Include="..\AccountingWarehouseProductsDataModels\AccountingWarehouseProductsDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,87 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Orders.Include(x => x.Products).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Orders.Include(x => x.Products).ThenInclude(x => x.Product).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Orders.Include(x => x.Products).ThenInclude(x => x.Product).Where(x => x.Id == model.Id).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Orders.Include(x => x.Products).ThenInclude(x => x.Product).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var newOrder = Models.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 AccountingWarehouseProductsDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class ProductStorage : IProductStorage
|
||||
{
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProductName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Products.Where(x => x.ProductName.Contains(model.ProductName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Products.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ProductViewModel? Delete(ProductBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Products.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Products.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Products.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName)) && x.ProductName == model.ProductName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Insert(ProductBindingModel model)
|
||||
{
|
||||
var newProduct = Product.Create(model);
|
||||
if (newProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
context.Products.Add(newProduct);
|
||||
context.SaveChanges();
|
||||
return newProduct.GetViewModel;
|
||||
}
|
||||
|
||||
public ProductViewModel? Update(ProductBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var component = context.Products.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class ShipmentStorage : IShipmentStorage
|
||||
{
|
||||
public List<ShipmentViewModel> GetFilteredList(ShipmentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Recipient))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Shipments.Where(x => x.Recipient.Contains(model.Recipient)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ShipmentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Shipments.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShipmentViewModel? Delete(ShipmentBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Shipments.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Shipments.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ShipmentViewModel? GetElement(ShipmentSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Shipments.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Recipient)) && x.Recipient == model.Recipient || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public ShipmentViewModel? Insert(ShipmentBindingModel model)
|
||||
{
|
||||
var newShipment = Shipment.Create(model);
|
||||
if (newShipment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
context.Shipments.Add(newShipment);
|
||||
context.SaveChanges();
|
||||
return newShipment.GetViewModel;
|
||||
}
|
||||
|
||||
public ShipmentViewModel? Update(ShipmentBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var component = context.Shipments.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class StandStorage : IStandStorage
|
||||
{
|
||||
public List<StandViewModel> GetFilteredList(StandSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.StandName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Stands.Where(x => x.StandName.Contains(model.StandName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<StandViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Stands.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public StandViewModel? Delete(StandBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Stands.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Stands.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public StandViewModel? GetElement(StandSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Stands.FirstOrDefault(x => (!string.IsNullOrEmpty(model.StandName)) && x.StandName == model.StandName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public StandViewModel? Insert(StandBindingModel model)
|
||||
{
|
||||
var newStand = Stand.Create(model);
|
||||
if (newStand == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
context.Stands.Add(newStand);
|
||||
context.SaveChanges();
|
||||
return newStand.GetViewModel;
|
||||
}
|
||||
|
||||
public StandViewModel? Update(StandBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var component = context.Stands.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class SupplierStorage : ISupplierStorage
|
||||
{
|
||||
public List<SupplierViewModel> GetFilteredList(SupplierSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SupplierName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Suppliers.Where(x => x.SupplierName.Contains(model.SupplierName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<SupplierViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Suppliers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public SupplierViewModel? Delete(SupplierBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Suppliers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Suppliers.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SupplierViewModel? GetElement(SupplierSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Suppliers.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SupplierName)) && x.SupplierName == model.SupplierName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public SupplierViewModel? Insert(SupplierBindingModel model)
|
||||
{
|
||||
var newSupplier = Supplier.Create(model);
|
||||
if (newSupplier == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
context.Suppliers.Add(newSupplier);
|
||||
context.SaveChanges();
|
||||
return newSupplier.GetViewModel;
|
||||
}
|
||||
|
||||
public SupplierViewModel? Update(SupplierBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var component = context.Suppliers.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.SearchModels;
|
||||
using AccountingWarehouseProductsContracts.StoragesContracts;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Implements
|
||||
{
|
||||
public class WarehouseStorage : IWarehouseStorage
|
||||
{
|
||||
public WarehouseViewModel? Delete(WarehouseBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var element = context.Warehouses.Include(x => x.Products).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Warehouses.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public WarehouseViewModel? GetElement(WarehouseSearchModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Warehouses.Include(x => x.Products).ThenInclude(x => x.Product).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<WarehouseViewModel> GetFilteredList(WarehouseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Warehouses.Include(x => x.Products).ThenInclude(x => x.Product).Where(x => x.Id == model.Id).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<WarehouseViewModel> GetFullList()
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
return context.Warehouses.Include(x => x.Products).ThenInclude(x => x.Product).ToList().Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public WarehouseViewModel? Insert(WarehouseBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
var newWarehouse = Models.Warehouse.Create(context, model);
|
||||
if (newWarehouse == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Warehouses.Add(newWarehouse);
|
||||
context.SaveChanges();
|
||||
return newWarehouse.GetViewModel;
|
||||
}
|
||||
|
||||
public WarehouseViewModel? Update(WarehouseBindingModel model)
|
||||
{
|
||||
using var context = new AccountingWarehouseProductsDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var warehouse = context.Warehouses.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (warehouse == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return warehouse.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,281 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AccountingWarehouseProductsDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AccountingWarehouseProductsDatabase))]
|
||||
[Migration("20240421151136_InitMigration")]
|
||||
partial class InitMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DateofOrder")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Category")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime?>("ExpirationDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Shipment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Recipient")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ShipmentDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shipments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Stand", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeliveryDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("StandName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("SupplierId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Stands");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Supplier", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ContactPerson")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Phone")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SupplierName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Suppliers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("WarehouseName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Warehouses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.WarehouseProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WarehouseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WarehouseId");
|
||||
|
||||
b.ToTable("WarehouseProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.WarehouseProduct", b =>
|
||||
{
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", "Warehouse")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("WarehouseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Warehouse");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
DateofOrder = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
Status = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Products",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ProductName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false),
|
||||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Category = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Products", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shipments",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShipmentDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Recipient = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
OrderId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shipments", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Stands",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
StandName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DeliveryDate = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||
SupplierId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Stands", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Suppliers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SupplierName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
ContactPerson = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Phone = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Suppliers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Warehouses",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WarehouseName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Capacity = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Warehouses", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "OrderProducts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
OrderId = table.Column<int>(type: "int", nullable: false),
|
||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_OrderProducts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderProducts_Orders_OrderId",
|
||||
column: x => x.OrderId,
|
||||
principalTable: "Orders",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_OrderProducts_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "WarehouseProducts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
WarehouseId = table.Column<int>(type: "int", nullable: false),
|
||||
ProductId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_WarehouseProducts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_WarehouseProducts_Products_ProductId",
|
||||
column: x => x.ProductId,
|
||||
principalTable: "Products",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_WarehouseProducts_Warehouses_WarehouseId",
|
||||
column: x => x.WarehouseId,
|
||||
principalTable: "Warehouses",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderProducts_OrderId",
|
||||
table: "OrderProducts",
|
||||
column: "OrderId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_OrderProducts_ProductId",
|
||||
table: "OrderProducts",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WarehouseProducts_ProductId",
|
||||
table: "WarehouseProducts",
|
||||
column: "ProductId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WarehouseProducts_WarehouseId",
|
||||
table: "WarehouseProducts",
|
||||
column: "WarehouseId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "OrderProducts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shipments");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Stands");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Suppliers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "WarehouseProducts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Products");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Warehouses");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,278 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using AccountingWarehouseProductsDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(AccountingWarehouseProductsDatabase))]
|
||||
partial class AccountingWarehouseProductsDatabaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.17")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime?>("DateofOrder")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OrderId");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Product", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Category")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.Property<DateTime?>("ExpirationDate")
|
||||
.IsRequired()
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("ProductName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Shipment", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("OrderId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("Recipient")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("ShipmentDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shipments");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Stand", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime?>("DeliveryDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("StandName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("SupplierId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Stands");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Supplier", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ContactPerson")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Phone")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("SupplierName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Suppliers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<int>("Capacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("WarehouseName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Warehouses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.WarehouseProduct", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ProductId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("WarehouseId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ProductId");
|
||||
|
||||
b.HasIndex("WarehouseId");
|
||||
|
||||
b.ToTable("WarehouseProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.OrderProduct", b =>
|
||||
{
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Order", "Order")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("OrderId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Order");
|
||||
|
||||
b.Navigation("Product");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.WarehouseProduct", b =>
|
||||
{
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Product", "Product")
|
||||
.WithMany()
|
||||
.HasForeignKey("ProductId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", "Warehouse")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("WarehouseId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Product");
|
||||
|
||||
b.Navigation("Warehouse");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountingWarehouseProductsDatabaseImplement.Models.Warehouse", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime? DateofOrder { get; set; }
|
||||
|
||||
public AccountingWarehouseProductsDataModels.Enums.OrderStatus Status { get; set; }
|
||||
|
||||
private Dictionary<int, (IProductModel, int)>? _orderProduct = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> OrderProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_orderProduct == null)
|
||||
{
|
||||
_orderProduct = Products.ToDictionary(recOP => recOP.ProductId, recOP => (recOP.Product as IProductModel, recOP.Count));
|
||||
}
|
||||
return _orderProduct;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("OrderId")]
|
||||
public virtual List<OrderProduct> Products { get; set; } = new();
|
||||
|
||||
public static Order Create(AccountingWarehouseProductsDatabase context, OrderBindingModel model)
|
||||
{
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
DateofOrder = model.DateofOrder,
|
||||
Status = model.Status,
|
||||
Products = model.OrderProducts.Select(x => new OrderProduct
|
||||
{
|
||||
Product = context.Products.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel model)
|
||||
{
|
||||
Status = model.Status;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DateofOrder = DateofOrder,
|
||||
Status = Status,
|
||||
OrderProducts = OrderProducts
|
||||
};
|
||||
|
||||
public void UpdateProducts(AccountingWarehouseProductsDatabase context, OrderBindingModel model)
|
||||
{
|
||||
var orderProducts = context.OrderProducts.Where(rec => rec.OrderId == model.Id).ToList();
|
||||
if (orderProducts != null && orderProducts.Count > 0)
|
||||
{
|
||||
context.OrderProducts.RemoveRange(orderProducts.Where(rec => !model.OrderProducts.ContainsKey(rec.ProductId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateProduct in orderProducts)
|
||||
{
|
||||
updateProduct.Count = model.OrderProducts[updateProduct.ProductId].Item2;
|
||||
model.OrderProducts.Remove(updateProduct.ProductId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var order = context.Orders.First(x => x.Id == Id);
|
||||
foreach (var rc in model.OrderProducts)
|
||||
{
|
||||
context.OrderProducts.Add(new OrderProduct
|
||||
{
|
||||
Order = order,
|
||||
Product = context.Products.First(x => x.Id == rc.Key),
|
||||
Count = rc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_orderProduct = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class OrderProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int OrderId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Order Order { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime? ExpirationDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Category { get; set; } = string.Empty;
|
||||
|
||||
public static Product? Create(ProductBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Product()
|
||||
{
|
||||
Id = model.Id,
|
||||
ProductName = model.ProductName,
|
||||
Cost = model.Cost,
|
||||
ExpirationDate = model.ExpirationDate,
|
||||
Category = model.Category
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ProductBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
ProductName = model.ProductName;
|
||||
Cost = model.Cost;
|
||||
ExpirationDate = model.ExpirationDate;
|
||||
Category = model.Category;
|
||||
}
|
||||
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ProductName = ProductName,
|
||||
Cost = Cost,
|
||||
ExpirationDate = ExpirationDate,
|
||||
Category = Category
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Shipment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime ShipmentDate { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Recipient { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int OrderId { get; set; }
|
||||
|
||||
public static Shipment? Create(ShipmentBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Shipment()
|
||||
{
|
||||
Id = model.Id,
|
||||
ShipmentDate = model.ShipmentDate,
|
||||
Count = model.Count,
|
||||
Recipient = model.Recipient,
|
||||
OrderId = model.OrderId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ShipmentBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
ShipmentDate = model.ShipmentDate;
|
||||
Count = model.Count;
|
||||
Recipient = model.Recipient;
|
||||
OrderId = model.OrderId;
|
||||
}
|
||||
|
||||
public ShipmentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ShipmentDate = ShipmentDate,
|
||||
Count = Count,
|
||||
Recipient = Recipient,
|
||||
OrderId = OrderId
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Stand
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string StandName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime? DeliveryDate { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public int SupplierId { get; set; }
|
||||
|
||||
public static Stand? Create(StandBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Stand()
|
||||
{
|
||||
Id = model.Id,
|
||||
StandName = model.StandName,
|
||||
DeliveryDate = model.DeliveryDate,
|
||||
Count = model.Count,
|
||||
ProductId = model.ProductId,
|
||||
SupplierId = model.SupplierId
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(StandBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
StandName = model.StandName;
|
||||
DeliveryDate = model.DeliveryDate;
|
||||
Count = model.Count;
|
||||
ProductId = model.ProductId;
|
||||
SupplierId = model.SupplierId;
|
||||
}
|
||||
|
||||
public StandViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StandName = StandName,
|
||||
DeliveryDate = DeliveryDate,
|
||||
Count = Count,
|
||||
ProductId = ProductId,
|
||||
SupplierId = SupplierId
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Supplier : ISupplierModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string SupplierName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string ContactPerson { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
|
||||
public static Supplier? Create(SupplierBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
|
||||
return new Supplier()
|
||||
{
|
||||
Id = model.Id,
|
||||
SupplierName = model.SupplierName,
|
||||
ContactPerson = model.ContactPerson,
|
||||
Phone = model.Phone
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(SupplierBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
SupplierName = model.SupplierName;
|
||||
ContactPerson = model.ContactPerson;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
|
||||
public SupplierViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SupplierName = SupplierName,
|
||||
ContactPerson = ContactPerson,
|
||||
Phone = Phone
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using AccountingWarehouseProductsContracts.BindingModels;
|
||||
using AccountingWarehouseProductsContracts.ViewModels;
|
||||
using AccountingWarehouseProductsDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class Warehouse
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string WarehouseName { get; set; } = string.Empty;
|
||||
|
||||
public string Address { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int Capacity { get; set; }
|
||||
|
||||
private Dictionary<int, (IProductModel, int)>? _warehouseProduct = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IProductModel, int)> WarehouseProducts
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_warehouseProduct == null)
|
||||
{
|
||||
_warehouseProduct = Products.ToDictionary(recWP => recWP.ProductId, recWP => (recWP.Product as IProductModel, recWP.Count));
|
||||
}
|
||||
return _warehouseProduct;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("WarehouseId")]
|
||||
public virtual List<WarehouseProduct> Products { get; set; } = new();
|
||||
|
||||
public static Warehouse Create(AccountingWarehouseProductsDatabase context, WarehouseBindingModel model)
|
||||
{
|
||||
return new Warehouse()
|
||||
{
|
||||
Id = model.Id,
|
||||
WarehouseName = model.WarehouseName,
|
||||
Address = model.Address,
|
||||
Capacity = model.Capacity,
|
||||
Products = model.WarehouseProducts.Select(x => new WarehouseProduct
|
||||
{
|
||||
Product = context.Products.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList(),
|
||||
};
|
||||
}
|
||||
|
||||
public WarehouseViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WarehouseName = WarehouseName,
|
||||
Address = Address,
|
||||
Capacity = Capacity,
|
||||
WarehouseProducts = WarehouseProducts
|
||||
};
|
||||
|
||||
public void UpdateProducts(AccountingWarehouseProductsDatabase context, WarehouseBindingModel model)
|
||||
{
|
||||
var warehouseProducts = context.WarehouseProducts.Where(rec => rec.WarehouseId == model.Id).ToList();
|
||||
if (warehouseProducts != null && warehouseProducts.Count > 0)
|
||||
{
|
||||
context.WarehouseProducts.RemoveRange(warehouseProducts.Where(rec => !model.WarehouseProducts.ContainsKey(rec.ProductId)));
|
||||
context.SaveChanges();
|
||||
|
||||
foreach (var updateProduct in warehouseProducts)
|
||||
{
|
||||
updateProduct.Count = model.WarehouseProducts[updateProduct.ProductId].Item2;
|
||||
model.WarehouseProducts.Remove(updateProduct.ProductId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var warehouse = context.Warehouses.First(x => x.Id == Id);
|
||||
foreach (var rc in model.WarehouseProducts)
|
||||
{
|
||||
context.WarehouseProducts.Add(new WarehouseProduct
|
||||
{
|
||||
Warehouse = warehouse,
|
||||
Product = context.Products.First(x => x.Id == rc.Key),
|
||||
Count = rc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_warehouseProduct = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AccountingWarehouseProductsDatabaseImplement.Models
|
||||
{
|
||||
public class WarehouseProduct
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int WarehouseId { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Warehouse Warehouse { get; set; } = new();
|
||||
public virtual Product Product { get; set; } = new();
|
||||
}
|
||||
}
|
@ -8,4 +8,15 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.17">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AccountingWarehouseProductsDatabaseImplement\AccountingWarehouseProductsDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user