Skip to content

Commit a5d7398

Browse files
Breakaway - solid (#14)
* Added Breakaway - SOLID * Added script for db setup
1 parent d0630f1 commit a5d7398

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+60862
-0
lines changed

Solid/SQL/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Database setup to run Breakaway Solid
2+
3+
- Install SQL Server (`choco install sql-server-2017`)
4+
- In SSMS
5+
- Connect to server COMPUTERNAME using Windows Authentication
6+
- Create new database named `Breakaway`
7+
- Run SQL script to create tables and insert data
8+
- In the solution, update the connection string in the `appsettings.json` with the COMPUTERNAME

Solid/SQL/breakaway_solid.sql

Lines changed: 20070 additions & 0 deletions
Large diffs are not rendered by default.

Solid/Solid.sln

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31105.61
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3813DBEA-DC1A-4AAB-B3BF-9428C6203022}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{63E321BB-D092-4B0F-BED8-6F69CBE9A4ED}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "src\Web\Web.csproj", "{51A0CBB7-2C24-4409-A334-6D6920D63219}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "src\Lib\Lib.csproj", "{381616DC-4DE6-42B6-B742-E2C75D7CAB6E}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Lib", "tests\Tests.Lib\Tests.Lib.csproj", "{BD6914FE-0DB1-45E8-9729-4299EAB96B44}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{CA691EB2-1CC2-40C3-96B4-8839270ABBD6}"
17+
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Storage", "src\Storage\Storage.csproj", "{3B1F7152-F89F-4660-9F25-CE3947E26F9A}"
19+
EndProject
20+
Global
21+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
22+
Debug|Any CPU = Debug|Any CPU
23+
Release|Any CPU = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
26+
{51A0CBB7-2C24-4409-A334-6D6920D63219}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{51A0CBB7-2C24-4409-A334-6D6920D63219}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{51A0CBB7-2C24-4409-A334-6D6920D63219}.Release|Any CPU.ActiveCfg = Release|Any CPU
29+
{51A0CBB7-2C24-4409-A334-6D6920D63219}.Release|Any CPU.Build.0 = Release|Any CPU
30+
{381616DC-4DE6-42B6-B742-E2C75D7CAB6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
31+
{381616DC-4DE6-42B6-B742-E2C75D7CAB6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
32+
{381616DC-4DE6-42B6-B742-E2C75D7CAB6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
33+
{381616DC-4DE6-42B6-B742-E2C75D7CAB6E}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{BD6914FE-0DB1-45E8-9729-4299EAB96B44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{BD6914FE-0DB1-45E8-9729-4299EAB96B44}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{BD6914FE-0DB1-45E8-9729-4299EAB96B44}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{BD6914FE-0DB1-45E8-9729-4299EAB96B44}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{CA691EB2-1CC2-40C3-96B4-8839270ABBD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{CA691EB2-1CC2-40C3-96B4-8839270ABBD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{CA691EB2-1CC2-40C3-96B4-8839270ABBD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{CA691EB2-1CC2-40C3-96B4-8839270ABBD6}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{3B1F7152-F89F-4660-9F25-CE3947E26F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{3B1F7152-F89F-4660-9F25-CE3947E26F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{3B1F7152-F89F-4660-9F25-CE3947E26F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{3B1F7152-F89F-4660-9F25-CE3947E26F9A}.Release|Any CPU.Build.0 = Release|Any CPU
46+
EndGlobalSection
47+
GlobalSection(SolutionProperties) = preSolution
48+
HideSolutionNode = FALSE
49+
EndGlobalSection
50+
GlobalSection(NestedProjects) = preSolution
51+
{51A0CBB7-2C24-4409-A334-6D6920D63219} = {3813DBEA-DC1A-4AAB-B3BF-9428C6203022}
52+
{381616DC-4DE6-42B6-B742-E2C75D7CAB6E} = {3813DBEA-DC1A-4AAB-B3BF-9428C6203022}
53+
{BD6914FE-0DB1-45E8-9729-4299EAB96B44} = {63E321BB-D092-4B0F-BED8-6F69CBE9A4ED}
54+
{CA691EB2-1CC2-40C3-96B4-8839270ABBD6} = {3813DBEA-DC1A-4AAB-B3BF-9428C6203022}
55+
{3B1F7152-F89F-4660-9F25-CE3947E26F9A} = {3813DBEA-DC1A-4AAB-B3BF-9428C6203022}
56+
EndGlobalSection
57+
GlobalSection(ExtensibilityGlobals) = postSolution
58+
SolutionGuid = {CF6BA94F-9A64-4A10-86D9-5BE4BF1089C9}
59+
EndGlobalSection
60+
EndGlobal

Solid/src/Domain/Deal.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Domain
4+
{
5+
public class Deal
6+
{
7+
public int Id { get; set; }
8+
public int SalesEmployeeId { get; set; }
9+
public string CustomerName { get; set; }
10+
public DateTime AgreementDate { get; set; }
11+
public decimal Price { get; set; }
12+
}
13+
}

Solid/src/Domain/Department.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Domain
2+
{
3+
public class Department
4+
{
5+
public int Id { get; set; }
6+
public string Name { get; set; }
7+
}
8+
}

Solid/src/Domain/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>

Solid/src/Domain/Employee.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Domain
5+
{
6+
public class Employee
7+
{
8+
public int Id { get; set; }
9+
public string Name { get; set; }
10+
public int DepartmentId { get; set; }
11+
public virtual Department Department { get; set; }
12+
public DateTime EmploymentStartDate { get; set; }
13+
public bool IsActive { get; set; }
14+
public virtual IEnumerable<TimeReport> TimeReports { get; set; }
15+
16+
public EmployeeType Type { get; set; }
17+
18+
public decimal? ManagerMonthlySalary { get; set; }
19+
20+
public decimal? StandardMonthlySalary { get; set; }
21+
22+
public decimal? SalesBaseSalary { get; set; }
23+
public decimal? SalesProvision { get; set; }
24+
public virtual IEnumerable<Deal> SalesDeals { get; set; }
25+
26+
public decimal? HourlySalary { get; set; }
27+
}
28+
29+
public enum EmployeeType
30+
{
31+
Manager = 1,
32+
Standard = 2,
33+
Sales = 3,
34+
Hourly = 4,
35+
Intern = 5
36+
}
37+
}

Solid/src/Domain/IRepository.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Linq;
2+
3+
namespace Domain
4+
{
5+
public interface IRepository
6+
{
7+
IQueryable<Employee> Employees { get; }
8+
IQueryable<Department> Departments { get; }
9+
}
10+
}

Solid/src/Domain/TimeReport.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Domain
4+
{
5+
public class TimeReport
6+
{
7+
public int Id { get; set; }
8+
public DateTime Date { get; set; }
9+
public int EmployeeId { get; set; }
10+
11+
public TimeReportType Type { get; set; }
12+
13+
public int? WorkingHours { get; set; }
14+
}
15+
16+
public enum TimeReportType
17+
{
18+
WorkingHours = 1,
19+
Vacation = 2,
20+
SickDay = 3
21+
}
22+
}

Solid/src/Lib/Lib.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>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using Domain;
2+
using Microsoft.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore.Metadata.Builders;
4+
5+
namespace Storage.Entities
6+
{
7+
public interface IBreakAwayContext
8+
{
9+
DbSet<Employee> Employees { get; }
10+
DbSet<Department> Departments { get; }
11+
}
12+
13+
public class BreakAwayContext : DbContext, IBreakAwayContext
14+
{
15+
public BreakAwayContext(DbContextOptions<BreakAwayContext> options) : base(options)
16+
{
17+
Employees = Set<Employee>();
18+
Departments = Set<Department>();
19+
}
20+
21+
public DbSet<Employee> Employees { get; }
22+
public DbSet<Department> Departments { get; }
23+
24+
protected override void OnModelCreating(ModelBuilder modelBuilder)
25+
{
26+
MapEmployee(modelBuilder.Entity<Employee>());
27+
MapDepartment(modelBuilder.Entity<Department>());
28+
MapDeal(modelBuilder.Entity<Deal>());
29+
MapTimeReport(modelBuilder.Entity<TimeReport>());
30+
}
31+
32+
private void MapEmployee(EntityTypeBuilder<Employee> entity)
33+
{
34+
entity.ToTable("Employees");
35+
36+
entity.HasKey(e => e.Id);
37+
38+
entity.Property(e => e.Id).HasColumnName("ID");
39+
40+
entity.Property(e => e.Name).HasColumnName("Name");
41+
42+
entity.Property(e => e.DepartmentId).HasColumnName("FKDepartmentID");
43+
44+
entity.Property(e => e.EmploymentStartDate).HasColumnName("EmploymentStartDate");
45+
46+
entity.Property(e => e.IsActive).HasColumnName("IsActive");
47+
48+
entity.Property(e => e.Type).HasColumnName("FKTypeID");
49+
50+
entity.Property(e => e.ManagerMonthlySalary).HasColumnName("ManagerMonthlySalary");
51+
52+
entity.Property(e => e.StandardMonthlySalary).HasColumnName("StandardMonthlySalary");
53+
54+
entity.Property(e => e.SalesBaseSalary).HasColumnName("SalesBaseSalary");
55+
56+
entity.Property(e => e.SalesProvision).HasColumnName("SalesProvision");
57+
58+
entity.Property(e => e.HourlySalary).HasColumnName("HourlySalary");
59+
60+
entity.HasOne(e => e.Department).WithMany().HasForeignKey(e => e.DepartmentId);
61+
62+
entity.HasMany(e => e.TimeReports).WithOne().HasForeignKey(e => e.EmployeeId);
63+
64+
entity.HasMany(e => e.SalesDeals).WithOne().HasForeignKey(e => e.SalesEmployeeId);
65+
}
66+
67+
private void MapDepartment(EntityTypeBuilder<Department> entity)
68+
{
69+
entity.ToTable("Departments");
70+
71+
entity.HasKey(e => e.Id);
72+
73+
entity.Property(e => e.Id).HasColumnName("ID");
74+
75+
entity.Property(e => e.Name).HasColumnName("Name");
76+
}
77+
78+
private void MapDeal(EntityTypeBuilder<Deal> entity)
79+
{
80+
entity.ToTable("Deals");
81+
82+
entity.HasKey(e => e.Id);
83+
84+
entity.Property(e => e.Id).HasColumnName("ID");
85+
86+
entity.Property(e => e.SalesEmployeeId).HasColumnName("FKSalesEmployeeID");
87+
88+
entity.Property(e => e.CustomerName).HasColumnName("CustomerName");
89+
90+
entity.Property(e => e.AgreementDate).HasColumnName("AgreementDate");
91+
92+
entity.Property(e => e.Price).HasColumnName("Price");
93+
}
94+
95+
private void MapTimeReport(EntityTypeBuilder<TimeReport> entity)
96+
{
97+
entity.ToTable("TimeReports");
98+
99+
entity.HasKey(e => e.Id);
100+
101+
entity.Property(e => e.Id).HasColumnName("ID");
102+
103+
entity.Property(e => e.Date).HasColumnName("Date");
104+
105+
entity.Property(e => e.EmployeeId).HasColumnName("FKEmployeeID");
106+
107+
entity.Property(e => e.Type).HasColumnName("FKTypeID");
108+
109+
entity.Property(e => e.WorkingHours).HasColumnName("HoursWorked");
110+
}
111+
}
112+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Linq;
3+
using Domain;
4+
5+
namespace Storage.Entities
6+
{
7+
public class SqlRepository : IRepository
8+
{
9+
private readonly IBreakAwayContext _context;
10+
11+
public SqlRepository(IBreakAwayContext context)
12+
{
13+
_context = context ?? throw new ArgumentNullException(nameof(context));
14+
}
15+
16+
public IQueryable<Employee> Employees => _context.Employees;
17+
public IQueryable<Department> Departments => _context.Departments;
18+
19+
}
20+
}

Solid/src/Storage/Storage.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="5.0.9" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Domain\Domain.csproj" />
13+
</ItemGroup>
14+
15+
</Project>

0 commit comments

Comments
 (0)