diff --git a/Models/Category.cs b/Models/Category.cs index b4b763d..42a047a 100644 --- a/Models/Category.cs +++ b/Models/Category.cs @@ -4,6 +4,7 @@ public class Category { public int Id { get; set;} public string Name { get; set;} + public string Description { get; set;} public ICollection Products { get; set; } } } \ No newline at end of file diff --git a/backend-ecommerce.csproj b/backend-ecommerce.csproj index 13a38b5..f2bb26c 100644 --- a/backend-ecommerce.csproj +++ b/backend-ecommerce.csproj @@ -16,6 +16,10 @@ all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/data/EcommerceContext.cs b/data/EcommerceContext.cs index b74b14b..9bf2fd7 100644 --- a/data/EcommerceContext.cs +++ b/data/EcommerceContext.cs @@ -16,6 +16,7 @@ public EcommerceContext(DbContextOptions options) : base(optio public DbSet Orders { get; set; } public DbSet OrderItems { get; set; } public DbSet Products { get; set; } + public DbSet Categories { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/script-all-database.sql b/script-all-database.sql new file mode 100644 index 0000000..78cb933 --- /dev/null +++ b/script-all-database.sql @@ -0,0 +1,81 @@ +IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL +BEGIN + CREATE TABLE [__EFMigrationsHistory] ( + [MigrationId] nvarchar(150) NOT NULL, + [ProductVersion] nvarchar(32) NOT NULL, + CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId]) + ); +END; +GO + +BEGIN TRANSACTION; +GO + +CREATE TABLE [Categories] ( + [Id] int NOT NULL IDENTITY, + [Name] nvarchar(max) NOT NULL, + [Description] nvarchar(max) NOT NULL, + CONSTRAINT [PK_Categories] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Users] ( + [Id] int NOT NULL IDENTITY, + [UserName] nvarchar(max) NOT NULL, + [Email] nvarchar(max) NOT NULL, + [PasswordHash] nvarchar(max) NULL, + [Access] nvarchar(max) NULL, + [Salt] nvarchar(max) NULL, + CONSTRAINT [PK_Users] PRIMARY KEY ([Id]) +); +GO + +CREATE TABLE [Products] ( + [Id] int NOT NULL IDENTITY, + [Name] nvarchar(max) NOT NULL, + [Description] nvarchar(max) NOT NULL, + [Price] decimal(18,2) NOT NULL, + [Stock] int NOT NULL, + [CategoryId] int NOT NULL, + CONSTRAINT [PK_Products] PRIMARY KEY ([Id]), + CONSTRAINT [FK_Products_Categories_CategoryId] FOREIGN KEY ([CategoryId]) REFERENCES [Categories] ([Id]) ON DELETE CASCADE +); +GO + +CREATE TABLE [Orders] ( + [Id] int NOT NULL IDENTITY, + [UserId] int NOT NULL, + [OrderDate] datetime2 NOT NULL, + [status] nvarchar(max) NOT NULL, + [total] decimal(18,2) NOT NULL, + CONSTRAINT [PK_Orders] PRIMARY KEY ([Id]), + CONSTRAINT [FK_Orders_Users_UserId] FOREIGN KEY ([UserId]) REFERENCES [Users] ([Id]) ON DELETE CASCADE +); +GO + +CREATE TABLE [OrderItems] ( + [Id] int NOT NULL IDENTITY, + [OrderId] int NOT NULL, + [ProductId] int NOT NULL, + [Quantity] int NOT NULL, + [UnitPrice] decimal(18,2) NOT NULL, + CONSTRAINT [PK_OrderItems] PRIMARY KEY ([Id]), + CONSTRAINT [FK_OrderItems_Orders_OrderId] FOREIGN KEY ([OrderId]) REFERENCES [Orders] ([Id]) ON DELETE CASCADE, + CONSTRAINT [FK_OrderItems_Products_ProductId] FOREIGN KEY ([ProductId]) REFERENCES [Products] ([Id]) ON DELETE CASCADE +); +GO + +CREATE INDEX [IX_OrderItems_OrderId] ON [OrderItems] ([OrderId]); +GO + +CREATE INDEX [IX_OrderItems_ProductId] ON [OrderItems] ([ProductId]); +GO + +CREATE INDEX [IX_Orders_UserId] ON [Orders] ([UserId]); +GO + +CREATE INDEX [IX_Products_CategoryId] ON [Products] ([CategoryId]); +GO + +COMMIT; +GO