Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Models/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Category
{
public int Id { get; set;}
public string Name { get; set;}
public string Description { get; set;}
public ICollection<Product> Products { get; set; }
}
}
4 changes: 4 additions & 0 deletions backend-ecommerce.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions data/EcommerceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public EcommerceContext(DbContextOptions<EcommerceContext> options) : base(optio
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }


protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down
81 changes: 81 additions & 0 deletions script-all-database.sql
Original file line number Diff line number Diff line change
@@ -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