Skip to content

Commit 7801c9e

Browse files
committed
Refactored code
1 parent 4d3f645 commit 7801c9e

34 files changed

+878
-0
lines changed

OA/OA.Data/CustomerContext.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using OA.Domain.Entities;
3+
4+
namespace OA.Data
5+
{
6+
public class CustomerContext : DbContext
7+
{
8+
// This constructor is used of runit testing
9+
public CustomerContext()
10+
{
11+
12+
}
13+
public CustomerContext(DbContextOptions options) : base(options)
14+
{
15+
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
16+
}
17+
18+
public DbSet<Customer> Customers { get; set; }
19+
public DbSet<Order> Orders { get; set; }
20+
public DbSet<Product> Products { get; set; }
21+
public DbSet<Category> Categories { get; set; }
22+
public DbSet<Supplier> Suppliers { get; set; }
23+
24+
protected override void OnModelCreating(ModelBuilder modelBuilder)
25+
{
26+
modelBuilder.Entity<OrderDetail>().HasKey(o => new { o.OrderId, o.ProductId });
27+
}
28+
29+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
30+
{
31+
if (!optionsBuilder.IsConfigured)
32+
{
33+
optionsBuilder
34+
.UseSqlServer("DataSource=app.db");
35+
}
36+
37+
}
38+
}
39+
}

OA/OA.Data/OA.Data.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\OA.Domain\OA.Domain.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

OA/OA.Domain/BaseEntity.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.ComponentModel.DataAnnotations;
2+
3+
namespace OA.Domain
4+
{
5+
public class BaseEntity
6+
{
7+
[Key]
8+
public int Id { get; set; }
9+
}
10+
}

OA/OA.Domain/Entities/Category.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Collections.Generic;
2+
3+
namespace OA.Domain.Entities
4+
{
5+
public class Category : BaseEntity
6+
{
7+
public string CategoryName { get; set; }
8+
public string Description { get; set; }
9+
public List<Product> Products { get; set; }
10+
}
11+
}

OA/OA.Domain/Entities/Customer.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Generic;
2+
3+
namespace OA.Domain.Entities
4+
{
5+
public class Customer : BaseEntity
6+
{
7+
public Customer()
8+
{
9+
Orders = new List<Order>();
10+
}
11+
public string CustomerName { get; set; }
12+
public string ContactName { get; set; }
13+
public string ContactTitle { get; set; }
14+
public string Address { get; set; }
15+
public string City { get; set; }
16+
public string Region { get; set; }
17+
public string PostalCode { get; set; }
18+
public string Country { get; set; }
19+
public string Phone { get; set; }
20+
public string Fax { get; set; }
21+
22+
public List<Order> Orders { get; set; }
23+
}
24+
}

OA/OA.Domain/Entities/Order.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace OA.Domain.Entities
5+
{
6+
public class Order : BaseEntity
7+
{
8+
public Customer Customers { get; set; }
9+
public int CustomerId { get; set; }
10+
public int EmployeeId { get; set; }
11+
public DateTime OrderDate { get; set; }
12+
public DateTime RequiredDate { get; set; }
13+
public List<OrderDetail> OrderDetails { get; set; }
14+
15+
}
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace OA.Domain.Entities
2+
{
3+
public class OrderDetail
4+
{
5+
public int OrderId { get; set; }
6+
public int ProductId { get; set; }
7+
public Order Orders { get; set; }
8+
public Product Product { get; set; }
9+
}
10+
}

OA/OA.Domain/Entities/Product.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.ComponentModel.DataAnnotations.Schema;
2+
3+
namespace OA.Domain.Entities
4+
{
5+
public class Product : BaseEntity
6+
{
7+
public string ProductName { get; set; }
8+
9+
[Column(TypeName = "money")]
10+
public decimal UnitPrice { get; set; }
11+
12+
}
13+
}

OA/OA.Domain/Entities/Supplier.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace OA.Domain.Entities
4+
{
5+
public class Supplier : BaseEntity
6+
{
7+
public string SupplierName { get; set; }
8+
public List<Product> Products { get; set; }
9+
}
10+
}

OA/OA.Domain/OA.Domain.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

0 commit comments

Comments
 (0)