Contractor: DataBase and Fixes

This commit is contained in:
Safgerd 2023-04-09 01:07:38 +04:00
parent 7cbd0a5e50
commit 769979a406
21 changed files with 1882 additions and 82 deletions

View File

@ -6,4 +6,15 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputerStoreDatabaseImplement\ComputerStoreDatabaseImplement.csproj" />
</ItemGroup>
</Project> </Project>

View File

@ -37,7 +37,7 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
{ {
PCName = pc.Name, PCName = pc.Name,
Components = new List<(string Component, int count)>(), Components = new List<(string Component, int count)>(),
Request = requests.Where(x => x.RequestProduct.First(y => y.ID == pc.ID)).Select(x => x.ID) //Request = requests.Where(x => x.RequestProduct.First(y => y.ID == pc.ID)).Select(x => x.ID)
}; };
@ -69,7 +69,7 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
foreach (var consignment in consignments) foreach (var consignment in consignments)
{ {
record.Consignments.Add(consignment.ConsignmentProducts.FirstOrDefault(x => x.ID == product.ID).Select(x => x.ID)); //record.Consignments.Add(consignment.ConsignmentProducts.FirstOrDefault(x => x.ID == product.ID).Select(x => x.ID));
} }
foreach (var component in product.ProductComponents) foreach (var component in product.ProductComponents)

View File

@ -98,7 +98,6 @@ namespace ComputerStoreBusinessLogic.BusinessLogic
if (!withParams) { return; } if (!withParams) { return; }
if (model.Price <= 0) { throw new ArgumentNullException("Invalid request's price", nameof(model)); } if (model.Price <= 0) { throw new ArgumentNullException("Invalid request's price", nameof(model)); }
if (string.IsNullOrEmpty(model.OrderID.ToString())) { throw new ArgumentNullException("Invalid Request's order ID", nameof(model)); } if (string.IsNullOrEmpty(model.OrderID.ToString())) { throw new ArgumentNullException("Invalid Request's order ID", nameof(model)); }
if (string.IsNullOrEmpty(model.PCID.ToString())) { throw new ArgumentNullException("Invalid Request's PC ID", nameof(model)); }
_logger.LogInformation("Request. Request ID:{ ID}. Order ID: { OrderID}. PC ID: { PCID}", model.ID, model.OrderID, model.PCID); _logger.LogInformation("Request. Request ID:{ ID}. Order ID: { OrderID}. PC ID: { PCID}", model.ID, model.OrderID, model.PCID);
} }

View File

@ -12,8 +12,8 @@ namespace ComputerStoreContracts.BindingModels
{ {
public int ID { get; set; } public int ID { get; set; }
public double Price { get; set; } public double Price { get; set; }
public List<IConsignmentModel> OrderConsignments { get; set; } = new(); public List<IConsignmentModel>? OrderConsignments { get; set; } = new();
public List<IRequestModel> OrderRequests { get; set; } = new(); public List<IRequestModel>? OrderRequests { get; set; } = new();
public OrderStatus Status { get; set; } = OrderStatus.Unknown; public OrderStatus Status { get; set; } = OrderStatus.Unknown;
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }

View File

@ -12,6 +12,6 @@ namespace ComputerStoreContracts.BindingModels
public int ID { get; set; } public int ID { get; set; }
public int OrderID { get; set; } public int OrderID { get; set; }
public double Price { get; set; } public double Price { get; set; }
public int PCID { get; set; } public int? PCID { get; set; }
} }
} }

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreContracts.BusinessLogicContracts
{
internal class ISellerReportLogic
{
}
}

View File

@ -26,7 +26,7 @@ namespace ComputerStoreContracts.ViewModels
[DisplayName("SellerUsername")] [DisplayName("SellerUsername")]
public string? SellerUsername { get; set; } = string.Empty; public string? SellerUsername { get; set; } = string.Empty;
public List<IConsignmentModel> OrderConsignments { get; set; } = new(); public List<IConsignmentModel>? OrderConsignments { get; set; } = new();
public List<IRequestModel> OrderRequests { get; set; } = new(); public List<IRequestModel>? OrderRequests { get; set; } = new();
} }
} }

View File

@ -18,6 +18,9 @@ namespace ComputerStoreContracts.ViewModels
public double Price { get; set; } public double Price { get; set; }
[DisplayName("PC ID")] [DisplayName("PC ID")]
public int PCID { get; set; } public int? PCID { get; set; }
[DisplayName("PC's name")]
public string PCName { get; set; } = string.Empty;
} }
} }

View File

@ -10,8 +10,8 @@ namespace ComputerStoreDataModels.Models
public interface IOrderModel : IID public interface IOrderModel : IID
{ {
double Price { get; } double Price { get; }
List<IConsignmentModel> OrderConsignments { get; } List<IConsignmentModel>? OrderConsignments { get; }
List<IRequestModel> OrderRequests { get; } List<IRequestModel>? OrderRequests { get; }
OrderStatus Status { get; } OrderStatus Status { get; }
DateTime DateCreate { get; } DateTime DateCreate { get; }
DateTime? DateImplement { get; } DateTime? DateImplement { get; }

View File

@ -9,7 +9,7 @@ namespace ComputerStoreDataModels.Models
public interface IRequestModel : IID public interface IRequestModel : IID
{ {
int OrderID { get; } int OrderID { get; }
int PCID { get; } int? PCID { get; }
double Price { get; } double Price { get; }
} }
} }

View File

@ -14,7 +14,7 @@ namespace ComputerStoreDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Initial Catalog=ComputerStoreDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Initial Catalog=ComputerStoreDatabase;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }
@ -25,5 +25,10 @@ namespace ComputerStoreDatabaseImplement
public virtual DbSet<Employee> Employees { get; set; } public virtual DbSet<Employee> Employees { get; set; }
public virtual DbSet<RequestComponent> RequestComponents { get; set; } public virtual DbSet<RequestComponent> RequestComponents { get; set; }
public virtual DbSet<ProductComponent> ProductComponents { get; set; } public virtual DbSet<ProductComponent> ProductComponents { get; set; }
public virtual DbSet<ConsignmentProduct> ConsignmentProducts { get; set; }
public virtual DbSet<Consignment> Consignments { get; set; }
public virtual DbSet<Order> Orders { get; set; }
public virtual DbSet<Request> Requests { get; set; }
public virtual DbSet<Seller> Sellers { get; set; }
} }
} }

View File

@ -1,13 +1,117 @@
using System; using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.SearchModels;
using ComputerStoreContracts.StorageContracts;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
namespace ComputerStoreDatabaseImplement.Implements namespace ComputerStoreDatabaseImplement.Implements
{ {
public class ConsignmentStorage //: IConsignmentStorage public class ConsignmentStorage : IConsignmentStorage
{ {
public List<ConsignmentViewModel> GetFullList()
{
using var context = new ComputerStoreDatabase();
return context.Consignments
.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ConsignmentViewModel> GetFilteredList(ConsignmentSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Consignments.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.Where(x =>
(!model.ID.HasValue || x.ID == model.ID) &&
(!model.OrderID.HasValue || x.OrderID == model.OrderID) &&
(!model.ProductID.HasValue || x.Products.FirstOrDefault(y => y.ProductID == model.ProductID) != null))
.Select(x => x.GetViewModel)
.ToList();
}
public ConsignmentViewModel? GetElement(ConsignmentSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Consignments.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x =>
(!model.ID.HasValue || x.ID == model.ID) &&
(!model.OrderID.HasValue || x.OrderID == model.OrderID) &&
(!model.ProductID.HasValue || x.Products.FirstOrDefault(y => y.ProductID == model.ProductID) != null))?
.GetViewModel;
}
public ConsignmentViewModel? Insert(ConsignmentBindingModel model)
{
using var context = new ComputerStoreDatabase();
var newConsignment = Consignment.Create(context, model);
if (newConsignment == null)
{
return null;
}
context.Consignments.Add(newConsignment);
context.SaveChanges();
return context.Consignments.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => x.ID == newConsignment.ID)?
.GetViewModel;
}
public ConsignmentViewModel? Update(ConsignmentBindingModel model)
{
using var context = new ComputerStoreDatabase();
var consignment = context.Consignments.Include(x => x.Products).FirstOrDefault(x => x.ID == model.ID);
if (consignment == null)
{
return null;
}
consignment.Update(model);
consignment.UpdateProducts(context, model);
context.SaveChanges();
return context.Consignments.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => x.ID == consignment.ID)?
.GetViewModel;
}
public ConsignmentViewModel? Delete(ConsignmentBindingModel model)
{
using var context = new ComputerStoreDatabase();
var consignment = context.Consignments.Include(x => x.Order)
.Include(x => x.Products)
.ThenInclude(x => x.Product)
.FirstOrDefault(x => x.ID == model.ID);
if (consignment != null)
{
context.Consignments.Remove(consignment);
context.SaveChanges();
return consignment.GetViewModel;
}
return null;
}
} }
} }

View File

@ -1,4 +1,10 @@
using System; using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.SearchModels;
using ComputerStoreContracts.StorageContracts;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +12,123 @@ using System.Threading.Tasks;
namespace ComputerStoreDatabaseImplement.Implements namespace ComputerStoreDatabaseImplement.Implements
{ {
public class OrderStorage //: IOrderStorage public class OrderStorage : IOrderStorage
{ {
public List<OrderViewModel> GetFullList()
{
using var context = new ComputerStoreDatabase();
return context.Orders.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Orders
.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.Where(x =>
(!model.ID.HasValue ||
x.ID == model.ID) &&
(!model.SellerID.HasValue ||
x.SellerID == model.SellerID) &&
(!model.ConsignmentID.HasValue ||
x._consignments.FirstOrDefault(y => y.ID == model.ConsignmentID) != null) &&
(!model.RequestID.HasValue ||
x._requests.FirstOrDefault(y => y.ID == model.RequestID) != null) &&
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo))
.Select(x => x.GetViewModel)
.ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Orders.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.FirstOrDefault(x =>
(!model.ID.HasValue ||
x.ID == model.ID) &&
(!model.SellerID.HasValue ||
x.SellerID == model.SellerID) &&
(!model.ConsignmentID.HasValue ||
x._consignments.FirstOrDefault(y => y.ID == model.ConsignmentID) != null) &&
(!model.RequestID.HasValue ||
x._requests.FirstOrDefault(y => y.ID == model.RequestID) != null) &&
(!model.DateFrom.HasValue || x.DateCreate >= model.DateFrom) &&
(!model.DateTo.HasValue || x.DateCreate <= model.DateTo))?
.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new ComputerStoreDatabase();
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
}
context.Orders.Add(newOrder);
context.SaveChanges();
return context.Orders.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.FirstOrDefault(x => x.ID == newOrder.ID)?
.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
using var context = new ComputerStoreDatabase();
var order = context.Orders
.Include(x => x._consignments)
.Include(x => x._requests)
.FirstOrDefault(x => x.ID == model.ID);
if (order == null)
{
return null;
}
order.Update(model);
order.UpdateOrderConsignments(context, model);
order.UpdateOrderRequests(context, model);
context.SaveChanges();
return context.Orders.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.FirstOrDefault(x => x.ID == model.ID)?
.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
using var context = new ComputerStoreDatabase();
var order = context.Orders.Include(x => x.Seller)
.Include(x => x._consignments)
.Include(x => x._requests)
.FirstOrDefault(x => x.ID == model.ID);
if (order != null)
{
context.Orders.Remove(order);
context.SaveChanges();
return order.GetViewModel;
}
return null;
}
} }
} }

View File

@ -1,4 +1,10 @@
using System; using ComputerStoreContracts.BindingModels;
using ComputerStoreContracts.SearchModels;
using ComputerStoreContracts.StorageContracts;
using ComputerStoreContracts.ViewModels;
using ComputerStoreDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +12,93 @@ using System.Threading.Tasks;
namespace ComputerStoreDatabaseImplement.Implements namespace ComputerStoreDatabaseImplement.Implements
{ {
public class RequestStorage //: IRequestStorage public class RequestStorage : IRequestStorage
{ {
public RequestViewModel? GetElement(RequestSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.FirstOrDefault(x =>
(!model.ID.HasValue || x.ID == model.ID) &&
(!model.OrderID.HasValue || x.OrderID == model.OrderID) &&
(!model.PCID.HasValue || x.PCID == model.PCID))?.GetViewModel;
}
public List<RequestViewModel> GetFilteredList(RequestSearchModel model)
{
using var context = new ComputerStoreDatabase();
return context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.Where(x =>
(!model.ID.HasValue || x.ID == model.ID) &&
(!model.OrderID.HasValue || x.OrderID == model.OrderID) &&
(!model.PCID.HasValue || x.PCID == model.PCID))
.Select(y => y.GetViewModel)
.ToList();
}
public List<RequestViewModel> GetFullList()
{
using var context = new ComputerStoreDatabase();
return context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.Select(y => y.GetViewModel)
.ToList();
}
public RequestViewModel? Insert(RequestBindingModel model)
{
using var context = new ComputerStoreDatabase();
var newRequest = Request.Create(context, model);
if (newRequest == null) { return null; }
context.Requests.Add(newRequest);
context.SaveChanges();
return context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
}
public RequestViewModel? Update(RequestBindingModel model)
{
using var context = new ComputerStoreDatabase();
var request = context.Requests.FirstOrDefault(x => x.ID == model.ID);
if (request == null)
{
return null;
}
request.Update(model);
context.SaveChanges();
return context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
}
public RequestViewModel? Delete(RequestBindingModel model)
{
using var context = new ComputerStoreDatabase();
var request = context.Requests
.Include(x => x.Order)
.Include(y => y.PCs)
.FirstOrDefault(x => x.ID == model.ID);
if (request != null)
{
context.Requests.Remove(request);
context.SaveChanges();
return request.GetViewModel;
}
return null;
}
} }
} }

View File

@ -0,0 +1,501 @@
// <auto-generated />
using System;
using ComputerStoreDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ComputerStoreDatabaseImplement.Migrations
{
[DbContext(typeof(ComputerStoreDatabase))]
[Migration("20230408204154_init")]
partial class init
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.ToTable("Components");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("OrderID");
b.HasIndex("ProductID");
b.ToTable("Consignments");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ConsignmentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ConsignmentID");
b.HasIndex("ProductID");
b.ToTable("ConsignmentProducts");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("MiddleName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Employees");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("SellerID")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("OrderID");
b.ToTable("Orders");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("RequestID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("PCs");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ComponentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ComponentID");
b.HasIndex("ProductID");
b.ToTable("ProductComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int?>("PCID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("OrderID");
b.ToTable("Requests");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ComponentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PCID")
.HasColumnType("int");
b.Property<int>("RequestID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ComponentID");
b.HasIndex("PCID");
b.HasIndex("RequestID");
b.ToTable("RequestComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("MiddleName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Sellers");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order")
.WithMany("_consignments")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null)
.WithMany("Consignments")
.HasForeignKey("ProductID");
b.Navigation("Order");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment")
.WithMany("Products")
.HasForeignKey("ConsignmentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Consignment");
b.Navigation("Product");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller")
.WithMany("Orders")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Seller");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee")
.WithMany("PCs")
.HasForeignKey("EmployeeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee")
.WithMany("Products")
.HasForeignKey("EmployeeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component")
.WithMany("ConsignmentComponents")
.HasForeignKey("ComponentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ProductID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Product");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order")
.WithMany("_requests")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component")
.WithMany("RequestComponents")
.HasForeignKey("ComponentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC")
.WithMany("Components")
.HasForeignKey("PCID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request")
.WithMany("PCs")
.HasForeignKey("RequestID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("PC");
b.Navigation("Request");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b =>
{
b.Navigation("ConsignmentComponents");
b.Navigation("RequestComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b =>
{
b.Navigation("PCs");
b.Navigation("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.Navigation("_consignments");
b.Navigation("_requests");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("Consignments");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.Navigation("PCs");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,367 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ComputerStoreDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Components",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Components", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Employees",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Username = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
MiddleName = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Employees", x => x.ID);
});
migrationBuilder.CreateTable(
name: "Sellers",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Username = table.Column<string>(type: "nvarchar(max)", nullable: false),
Password = table.Column<string>(type: "nvarchar(max)", nullable: false),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
MiddleName = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Sellers", x => x.ID);
});
migrationBuilder.CreateTable(
name: "PCs",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
EmployeeID = table.Column<int>(type: "int", nullable: false),
RequestID = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PCs", x => x.ID);
table.ForeignKey(
name: "FK_PCs_Employees_EmployeeID",
column: x => x.EmployeeID,
principalTable: "Employees",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Products",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
EmployeeID = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.ID);
table.ForeignKey(
name: "FK_Products_Employees_EmployeeID",
column: x => x.EmployeeID,
principalTable: "Employees",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Price = table.Column<double>(type: "float", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
SellerID = table.Column<int>(type: "int", nullable: false),
OrderID = table.Column<int>(type: "int", nullable: false),
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.ID);
table.ForeignKey(
name: "FK_Orders_Sellers_OrderID",
column: x => x.OrderID,
principalTable: "Sellers",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProductComponents",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ComponentID = 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_ProductComponents", x => x.ID);
table.ForeignKey(
name: "FK_ProductComponents_Components_ComponentID",
column: x => x.ComponentID,
principalTable: "Components",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProductComponents_Products_ProductID",
column: x => x.ProductID,
principalTable: "Products",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Consignments",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderID = table.Column<int>(type: "int", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
ProductID = table.Column<int>(type: "int", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Consignments", x => x.ID);
table.ForeignKey(
name: "FK_Consignments_Orders_OrderID",
column: x => x.OrderID,
principalTable: "Orders",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Consignments_Products_ProductID",
column: x => x.ProductID,
principalTable: "Products",
principalColumn: "ID");
});
migrationBuilder.CreateTable(
name: "Requests",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
OrderID = table.Column<int>(type: "int", nullable: false),
PCID = table.Column<int>(type: "int", nullable: true),
Price = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Requests", x => x.ID);
table.ForeignKey(
name: "FK_Requests_Orders_OrderID",
column: x => x.OrderID,
principalTable: "Orders",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ConsignmentProducts",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ConsignmentID = 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_ConsignmentProducts", x => x.ID);
table.ForeignKey(
name: "FK_ConsignmentProducts_Consignments_ConsignmentID",
column: x => x.ConsignmentID,
principalTable: "Consignments",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ConsignmentProducts_Products_ProductID",
column: x => x.ProductID,
principalTable: "Products",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "RequestComponents",
columns: table => new
{
ID = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RequestID = table.Column<int>(type: "int", nullable: false),
ComponentID = table.Column<int>(type: "int", nullable: false),
PCID = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RequestComponents", x => x.ID);
table.ForeignKey(
name: "FK_RequestComponents_Components_ComponentID",
column: x => x.ComponentID,
principalTable: "Components",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RequestComponents_PCs_PCID",
column: x => x.PCID,
principalTable: "PCs",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_RequestComponents_Requests_RequestID",
column: x => x.RequestID,
principalTable: "Requests",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ConsignmentProducts_ConsignmentID",
table: "ConsignmentProducts",
column: "ConsignmentID");
migrationBuilder.CreateIndex(
name: "IX_ConsignmentProducts_ProductID",
table: "ConsignmentProducts",
column: "ProductID");
migrationBuilder.CreateIndex(
name: "IX_Consignments_OrderID",
table: "Consignments",
column: "OrderID");
migrationBuilder.CreateIndex(
name: "IX_Consignments_ProductID",
table: "Consignments",
column: "ProductID");
migrationBuilder.CreateIndex(
name: "IX_Orders_OrderID",
table: "Orders",
column: "OrderID");
migrationBuilder.CreateIndex(
name: "IX_PCs_EmployeeID",
table: "PCs",
column: "EmployeeID");
migrationBuilder.CreateIndex(
name: "IX_ProductComponents_ComponentID",
table: "ProductComponents",
column: "ComponentID");
migrationBuilder.CreateIndex(
name: "IX_ProductComponents_ProductID",
table: "ProductComponents",
column: "ProductID");
migrationBuilder.CreateIndex(
name: "IX_Products_EmployeeID",
table: "Products",
column: "EmployeeID");
migrationBuilder.CreateIndex(
name: "IX_RequestComponents_ComponentID",
table: "RequestComponents",
column: "ComponentID");
migrationBuilder.CreateIndex(
name: "IX_RequestComponents_PCID",
table: "RequestComponents",
column: "PCID");
migrationBuilder.CreateIndex(
name: "IX_RequestComponents_RequestID",
table: "RequestComponents",
column: "RequestID");
migrationBuilder.CreateIndex(
name: "IX_Requests_OrderID",
table: "Requests",
column: "OrderID");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ConsignmentProducts");
migrationBuilder.DropTable(
name: "ProductComponents");
migrationBuilder.DropTable(
name: "RequestComponents");
migrationBuilder.DropTable(
name: "Consignments");
migrationBuilder.DropTable(
name: "Components");
migrationBuilder.DropTable(
name: "PCs");
migrationBuilder.DropTable(
name: "Requests");
migrationBuilder.DropTable(
name: "Products");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Employees");
migrationBuilder.DropTable(
name: "Sellers");
}
}
}

View File

@ -0,0 +1,498 @@
// <auto-generated />
using System;
using ComputerStoreDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace ComputerStoreDatabaseImplement.Migrations
{
[DbContext(typeof(ComputerStoreDatabase))]
partial class ComputerStoreDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.ToTable("Components");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("OrderID");
b.HasIndex("ProductID");
b.ToTable("Consignments");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ConsignmentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ConsignmentID");
b.HasIndex("ProductID");
b.ToTable("ConsignmentProducts");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("MiddleName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Employees");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<DateTime>("DateCreate")
.HasColumnType("datetime2");
b.Property<DateTime?>("DateImplement")
.HasColumnType("datetime2");
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("SellerID")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("OrderID");
b.ToTable("Orders");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("RequestID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("PCs");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("EmployeeID")
.HasColumnType("int");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("EmployeeID");
b.ToTable("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ComponentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("ProductID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ComponentID");
b.HasIndex("ProductID");
b.ToTable("ProductComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("OrderID")
.HasColumnType("int");
b.Property<int?>("PCID")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("ID");
b.HasIndex("OrderID");
b.ToTable("Requests");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<int>("ComponentID")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("PCID")
.HasColumnType("int");
b.Property<int>("RequestID")
.HasColumnType("int");
b.HasKey("ID");
b.HasIndex("ComponentID");
b.HasIndex("PCID");
b.HasIndex("RequestID");
b.ToTable("RequestComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b =>
{
b.Property<int>("ID")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("ID"));
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<string>("MiddleName")
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("ID");
b.ToTable("Sellers");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order")
.WithMany("_consignments")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", null)
.WithMany("Consignments")
.HasForeignKey("ProductID");
b.Navigation("Order");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ConsignmentProduct", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Consignment", "Consignment")
.WithMany("Products")
.HasForeignKey("ConsignmentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product")
.WithMany()
.HasForeignKey("ProductID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Consignment");
b.Navigation("Product");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Seller", "Seller")
.WithMany("Orders")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Seller");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee")
.WithMany("PCs")
.HasForeignKey("EmployeeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Employee", "Employee")
.WithMany("Products")
.HasForeignKey("EmployeeID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Employee");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.ProductComponent", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component")
.WithMany("ConsignmentComponents")
.HasForeignKey("ComponentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Product", "Product")
.WithMany("Components")
.HasForeignKey("ProductID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("Product");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Order", "Order")
.WithMany("_requests")
.HasForeignKey("OrderID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.RequestComponent", b =>
{
b.HasOne("ComputerStoreDatabaseImplement.Models.Component", "Component")
.WithMany("RequestComponents")
.HasForeignKey("ComponentID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.PC", "PC")
.WithMany("Components")
.HasForeignKey("PCID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ComputerStoreDatabaseImplement.Models.Request", "Request")
.WithMany("PCs")
.HasForeignKey("RequestID")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Component");
b.Navigation("PC");
b.Navigation("Request");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Component", b =>
{
b.Navigation("ConsignmentComponents");
b.Navigation("RequestComponents");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Consignment", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Employee", b =>
{
b.Navigation("PCs");
b.Navigation("Products");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Order", b =>
{
b.Navigation("_consignments");
b.Navigation("_requests");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.PC", b =>
{
b.Navigation("Components");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Product", b =>
{
b.Navigation("Components");
b.Navigation("Consignments");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Request", b =>
{
b.Navigation("PCs");
});
modelBuilder.Entity("ComputerStoreDatabaseImplement.Models.Seller", b =>
{
b.Navigation("Orders");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -8,6 +8,7 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Runtime.ConstrainedExecution;
namespace ComputerStoreDatabaseImplement.Models namespace ComputerStoreDatabaseImplement.Models
{ {
@ -17,6 +18,7 @@ namespace ComputerStoreDatabaseImplement.Models
[Required] [Required]
public int OrderID { get; private set; } public int OrderID { get; private set; }
public virtual Order Order { get; set; }
[Required] [Required]
public double Price { get; private set; } public double Price { get; private set; }
@ -36,60 +38,72 @@ namespace ComputerStoreDatabaseImplement.Models
} }
} }
[ForeignKey("ConsignmentId")]
public virtual List<CarComponent> Components { get; set; } = new();
public virtual Product Product { get; private set; }
private Dictionary<int, (IProductModel, int)>? Products = null;
[ForeignKey("ConsignmentID")] [ForeignKey("ConsignmentID")]
public virtual List<ConsignmentComponent> ConsignmentComponent { get; private set; } = new(); public virtual List<ConsignmentProduct> Products { get; set; } = new();
public static Consignment Create(ComputerStoreDatabase context, ConsignmentBindingModel model) public static Consignment? Create(ComputerStoreDatabase context, ConsignmentBindingModel model)
{ {
if (model == null) if (model == null)
{ {
return null; return null;
} }
var products = context.Products;
return new Consignment() return new Consignment()
{ {
ID = model.ID, ID = model.ID,
OrderID = model.OrderID, OrderID = model.OrderID,
Price = model.Price, Price = model.Price,
_orderProducts = model.ConsignmentProducts Products = model.ConsignmentProducts.Select(x => new ConsignmentProduct
{
Product = context.Products.First(y => y.ID == x.Key),
Count = x.Value.Item2
}).ToList()
}; };
//return new Consignment()
//{
// ID = model.ID,
// OrderID = model.OrderID,
// Price = model.Price,
// Products = model.ConsignmentProducts.Select(x => new ConsignmentComponent
// {
// Component = context.Components.First(y => y.ID == x.Key),
// Count = x.Value.Item2
// }).ToList()
//};
} }
public void Update(ConsignmentBindingModel? model)
public void Update(ConsignmentBindingModel model)
{ {
if (model == null) if (model == null)
{ {
return; return;
} }
OrderID = model.OrderID;
Price = model.Price; Price = model.Price;
} }
public ConsignmentViewModel GetViewModel => new() public ConsignmentViewModel GetViewModel => new()
{ {
ID = ID, ID = ID,
OrderID = OrderID, OrderID = OrderID,
Price = Price Price = Price,
ConsignmentProducts = ConsignmentProducts
}; };
public void UpdateProducts(ComputerStoreDatabase context, ConsignmentBindingModel model)
{
var consignmentProducts = context.ConsignmentProducts.Where(rec => rec.ConsignmentID == model.ID).ToList();
if (consignmentProducts != null && consignmentProducts.Count > 0)
{
context.ConsignmentProducts.RemoveRange(consignmentProducts.Where(rec => !model.ConsignmentProducts.ContainsKey(rec.ProductID)));
context.SaveChanges();
foreach (var updateProduct in consignmentProducts)
{
updateProduct.Count = model.ConsignmentProducts[updateProduct.ID].Item2;
model.ConsignmentProducts.Remove(updateProduct.ID);
}
context.SaveChanges();
}
var consignment = context.Consignments.First(x => x.ID == ID);
foreach (var pc in model.ConsignmentProducts)
{
context.ConsignmentProducts.Add(new ConsignmentProduct
{
Consignment = consignment,
Product = context.Products.First(x => x.ID == pc.Key),
Count = pc.Value.Item2
});
context.SaveChanges();
}
_consignmentProducts = null;
}
} }
} }

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace ComputerStoreDatabaseImplement.Models
{
public class ConsignmentProduct
{
public int ID { get; set; }
[Required]
public int ConsignmentID { get; set; }
[Required]
public int ProductID { get; set; }
[Required]
public int Count { get; set; }
public virtual Consignment Consignment { get; set; } = new();
public virtual Product Product { get; set; } = new();
}
}

View File

@ -16,30 +16,39 @@ namespace ComputerStoreDatabaseImplement.Models
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int ID { get; private set; } public int ID { get; private set; }
[Required] [Required]
public double Price { get; private set; } public double Price { get; private set; }
public int? ConsignmentID { get; private set; }
public int? RequestID { get; private set; }
[Required] [Required]
public OrderStatus Status { get; private set; } = OrderStatus.Unknown; public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
[Required]
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
[Required] [Required]
public int SellerID { get; private set; } public int SellerID { get; private set; }
public virtual Seller Seller { get; set; } public virtual Seller Seller { get; set; }
public virtual Consignment Consignment { get; private set; } [Required]
public virtual Request Request { get; private set; } public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model) [ForeignKey("OrderID")]
public virtual List<Consignment> _consignments { get; private set; } = new();
[ForeignKey("OrderID")]
public virtual List<Request> _requests { get; private set; } = new();
[NotMapped]
public List<IConsignmentModel> OrderConsignments
{
get
{
return _consignments.Select(x => (IConsignmentModel)x).ToList();
}
}
[NotMapped]
public List<IRequestModel> OrderRequests
{
get
{
return _requests.Select(x => (IRequestModel)x).ToList();
}
}
public static Order? Create(ComputerStoreDatabase context, OrderBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@ -47,15 +56,15 @@ namespace ComputerStoreDatabaseImplement.Models
} }
return new Order return new Order
{ {
ID = model.ID,
Price = model.Price, Price = model.Price,
ConsignmentID = model.ConsignmentID,
RequestID = model.RequestID,
Status = model.Status, Status = model.Status,
SellerID = model.SellerID,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
DateImplement = model.DateImplement, DateImplement = model.DateImplement,
SellerID = model.SellerID, _consignments = model.OrderConsignments.Select(x => context.Consignments.First(y => y.ID == x.ID)).ToList(),
ID = model.ID, _requests = model.OrderRequests.Select(x => context.Requests.First(y => y.ID == x.ID)).ToList(),
}; };
} }
public void Update(OrderBindingModel? model) public void Update(OrderBindingModel? model)
@ -66,6 +75,24 @@ namespace ComputerStoreDatabaseImplement.Models
} }
Status = model.Status; Status = model.Status;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
Price = model.Price;
}
public void UpdateOrderRequests(ComputerStoreDatabase context, OrderBindingModel model)
{
if (model.OrderRequests == null)
{
return;
}
_requests = model.OrderRequests.Select(x => context.Requests.First(y => y.ID == x.ID)).ToList();
}
public void UpdateOrderConsignments(ComputerStoreDatabase context, OrderBindingModel model)
{
if (model.OrderRequests == null)
{
return;
}
_consignments = model.OrderConsignments.Select(x => context.Consignments.First(y => y.ID == x.ID)).ToList();
} }
public OrderViewModel GetViewModel public OrderViewModel GetViewModel
@ -77,14 +104,14 @@ namespace ComputerStoreDatabaseImplement.Models
{ {
ID = ID, ID = ID,
ConsignmentID = ConsignmentID, Price = Price,
RequestID = RequestID,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
Status = Status, Status = Status,
Price = Price,
SellerID = SellerID, SellerID = SellerID,
SellerUsername = context.Sellers.FirstOrDefault(x => x.ID == SellerID)?.Username ?? string.Empty SellerUsername = context.Sellers.First(x => x.ID == SellerID)?.Username ?? string.Empty,
OrderConsignments = _consignments.Select(x => (IConsignmentModel)x.GetViewModel).ToList(),
OrderRequests = _requests.Select(x => (IRequestModel)x.GetViewModel).ToList()
}; };
} }
} }

View File

@ -8,6 +8,10 @@ using System.ComponentModel.DataAnnotations;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Azure.Core;
using ComputerStoreContracts.SearchModels;
using Microsoft.EntityFrameworkCore;
using System.Xml.Linq;
namespace ComputerStoreDatabaseImplement.Models namespace ComputerStoreDatabaseImplement.Models
{ {
@ -17,14 +21,17 @@ namespace ComputerStoreDatabaseImplement.Models
[Required] [Required]
public int OrderID { get; private set; } public int OrderID { get; private set; }
public virtual Order Order { get; set; }
public int? PCID { get; private set; }
[Required] [Required]
public double Price { get; private set; } public double Price { get; private set; }
[ForeignKey("RequestID")] [ForeignKey("RequestID")]
public virtual List<RequestComponent> RequestComponents { get; private set; } = new(); public virtual List<RequestComponent> PCs { get; set; } = new();
public static Request? Create(RequestBindingModel model) public static Request? Create(ComputerStoreDatabase context, RequestBindingModel model)
{ {
if (model == null) if (model == null)
{ {
@ -38,21 +45,35 @@ namespace ComputerStoreDatabaseImplement.Models
}; };
} }
public void Update(RequestBindingModel? model) public void Update(RequestBindingModel model)
{ {
if (model == null) if (model == null)
{ {
return; return;
} }
OrderID = model.OrderID;
Price = model.Price; Price = model.Price;
PCID = model.PCID;
} }
public RequestViewModel GetViewModel => new() public void UpdatePCID(ComputerStoreDatabase context)
{ {
ID = ID, PCID = context.RequestComponents.First(x => x.RequestID == ID).PCID;
OrderID = OrderID, }
Price = Price
}; public RequestViewModel GetViewModel
{
get
{
var context = new ComputerStoreDatabase();
return new RequestViewModel()
{
ID = ID,
OrderID = OrderID,
Price = Price,
PCID = PCID,
PCName = context.PCs.First(rec => rec.ID == PCID).Name
};
}
}
} }
} }