├── .gitattributes ├── .gitignore ├── Northwind.DDD ├── Northwind.Application │ ├── Categories │ │ ├── CategoryDto.cs │ │ ├── CategoryManager.cs │ │ └── CategoryRepository.cs │ ├── Customers │ │ ├── CustomerDto.cs │ │ └── CustomerService.cs │ ├── Database │ │ ├── NorthwindDbContext.cs │ │ └── UnitOfWork.cs │ ├── Employees │ │ ├── EmployeeDto.cs │ │ ├── EmployeeManager.cs │ │ └── EmployeeRepository.cs │ ├── ExtensionRegistery.cs │ ├── Mappers │ │ ├── CategoryMapper.cs │ │ ├── EmployeeMapper.cs │ │ └── ProductMapper.cs │ ├── Migrations │ │ ├── 20171101075051_CreateDatabase.Designer.cs │ │ ├── 20171101075051_CreateDatabase.cs │ │ ├── 20171101081850_OrderRelation.Designer.cs │ │ ├── 20171101081850_OrderRelation.cs │ │ ├── 20171101084922_OrderDetailsAndRelation.Designer.cs │ │ ├── 20171101084922_OrderDetailsAndRelation.cs │ │ ├── 20171101085136_SuppliersMigration.Designer.cs │ │ ├── 20171101085136_SuppliersMigration.cs │ │ ├── 20171101085257_SuppliersMigrationRollback.Designer.cs │ │ ├── 20171101085257_SuppliersMigrationRollback.cs │ │ ├── 20171108132241_EmployeeManagerId.Designer.cs │ │ ├── 20171108132241_EmployeeManagerId.cs │ │ └── NorthwindDbContextModelSnapshot.cs │ ├── Northwind.Application.csproj │ ├── OrderDetails │ │ ├── OrderDetailDto.cs │ │ └── OrderDetailService.cs │ ├── Orders │ │ ├── OrderDto.cs │ │ └── OrderService.cs │ ├── Products │ │ ├── ProductDto.cs │ │ ├── ProductManager.cs │ │ └── ProductRepository.cs │ └── Suppliers │ │ ├── SupplierDto.cs │ │ └── SupplierService.cs ├── Northwind.DDD.sln ├── Northwind.DataBase │ ├── Data │ │ ├── Categories.sql │ │ ├── Employees.sql │ │ ├── Products.sql │ │ └── Suppliers.sql │ └── Northwind.DataBase.sqlproj ├── Northwind.Domain │ ├── Categories │ │ ├── Category.cs │ │ └── ICategoryRepository.cs │ ├── Customers │ │ ├── Customer.cs │ │ ├── CustomerCodeInvalidException.cs │ │ ├── CustomerPolicy.cs │ │ └── ICustomerRepository.cs │ ├── Employees │ │ ├── Employee.cs │ │ ├── EmployeePolicy.cs │ │ ├── HasManagerFilter.cs │ │ ├── HasNoManagerFilter.cs │ │ ├── IEmployeeRepository.cs │ │ └── NameIsTooShortException.cs │ ├── Northwind.Domain.csproj │ ├── OrderDetails │ │ ├── IOrderDetailRepository.cs │ │ ├── InvalidOrderPriceException.cs │ │ ├── InvalidOrderQuantityException.cs │ │ ├── OrderDetail.cs │ │ └── OrderDetailPolicy.cs │ ├── Orders │ │ ├── IOrderRepository.cs │ │ └── Order.cs │ ├── Products │ │ ├── IProductRepository.cs │ │ ├── InvalidPriceException.cs │ │ ├── InvalidStockException.cs │ │ ├── Product.cs │ │ ├── ProductByCategoryFilter.cs │ │ └── ProductPolicy.cs │ └── Suppliers │ │ ├── ISupplierRepository.cs │ │ └── Supplier.cs ├── Northwind.Framework │ ├── Domain │ │ ├── CommonPolicy.cs │ │ ├── ExceptionType.cs │ │ ├── Exceptions │ │ │ ├── Handler │ │ │ │ └── NorthwindExceptionHandler.cs │ │ │ ├── InvalidEMailException.cs │ │ │ ├── InvalidValueAsIdException.cs │ │ │ └── NotFoundByIdException.cs │ │ ├── Infrastructure │ │ │ └── IDomainService.cs │ │ └── OperationalException.cs │ ├── Entity │ │ ├── EntityBase.cs │ │ └── IEntityKey.cs │ ├── Helpers │ │ ├── Constants │ │ │ └── RegexContants.cs │ │ ├── Domain │ │ │ ├── DomianEvent.cs │ │ │ ├── IDomainService.cs │ │ │ └── IEventHandler.cs │ │ ├── Filters │ │ │ ├── FilterBase.cs │ │ │ └── IFilter.cs │ │ └── Repository │ │ │ ├── IRepository.cs │ │ │ └── IUnitOfWork.cs │ ├── Northwind.Framework.csproj │ └── TypeCheck.cs ├── Northwind.UnitTests │ ├── CategoryTest.cs │ ├── EmployeeTest.cs │ ├── Northwind.UnitTests.csproj │ ├── UnitTestBase.cs │ └── appSettings.json └── Northwind.Web │ ├── Controllers │ └── HomeController.cs │ ├── Models │ ├── CategoryViewModel.cs │ ├── CustomerViewModel.cs │ ├── EmployeeViewModel.cs │ ├── OrderViewModel.cs │ ├── ProductViewModel.cs │ └── SupplierViewModel.cs │ ├── Northwind.Web.csproj │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ └── appSettings.json └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Categories/CategoryDto.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Application.Categories 2 | { 3 | public class CategoryDto 4 | { 5 | public int Id { get; set; } 6 | public string Name { get; set; } 7 | public string Decription { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Categories/CategoryManager.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Mappers; 2 | using Northwind.Application.Products; 3 | using Northwind.Domain.Categories; 4 | using Northwind.Domain.Products; 5 | using Northwind.Framework.Domain; 6 | using Northwind.Framework.Helpers; 7 | using System.Collections.Generic; 8 | 9 | namespace Northwind.Application.Categories 10 | { 11 | public class CategoryManager : IDomainService 12 | { 13 | private readonly ICategoryRepository _categoryRepo; 14 | private readonly IProductRepository _productRepo; 15 | private readonly IUnitOfWork _unitOfWork; 16 | 17 | public CategoryManager(IUnitOfWork unitOfWork, ICategoryRepository categoryRepository, IProductRepository productRepository) 18 | { 19 | _categoryRepo = categoryRepository; 20 | _productRepo = productRepository; 21 | _unitOfWork = unitOfWork; 22 | } 23 | 24 | public bool HasProducts(CategoryDto category) 25 | { 26 | return true; 27 | } 28 | 29 | public CategoryDto GetById(int id) 30 | { 31 | var category = _categoryRepo.FindById(id); 32 | return category.ToDto(); 33 | } 34 | 35 | public IEnumerable GetProducts(CategoryDto category) 36 | { 37 | var entity = category.ToEntity(); 38 | var productManager = new ProductManager(_productRepo, _unitOfWork); 39 | return productManager.GetProductsByCategory(entity); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Categories/CategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Categories; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore; 4 | using Northwind.Framework.Helpers; 5 | using System.Linq; 6 | using Northwind.Framework.Domain.Exceptions; 7 | 8 | namespace Northwind.Application.Categories 9 | { 10 | internal class CategoryRepository : ICategoryRepository 11 | { 12 | private readonly IUnitOfWork _unitOfwork; 13 | public CategoryRepository(IUnitOfWork unitOfwork) 14 | { 15 | _unitOfwork = unitOfwork; 16 | } 17 | public DbSet Repository => _unitOfwork.GetDbSet(); 18 | public IEnumerable Find(IFilter filter) 19 | { 20 | return Repository.Where(filter.FilterExpression); 21 | } 22 | 23 | public Category FindById(int id) 24 | { 25 | var category = Repository.FirstOrDefault(i => i.Id == id); 26 | if (category == null) 27 | { 28 | throw new NotFoundByIdException(); 29 | } 30 | return category; 31 | } 32 | 33 | public Category FindSingle(IFilter spec) 34 | { 35 | return Repository.Where(spec.FilterExpression).SingleOrDefault(); 36 | } 37 | 38 | public void Remove(Category entity) 39 | { 40 | Repository.Remove(entity); 41 | } 42 | 43 | public void Save(Category entity) 44 | { 45 | Repository.Add(entity); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Customers/CustomerDto.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Application.Customers 2 | { 3 | public class CustomerDto 4 | { 5 | public string Id { get; set; } 6 | public string Title { get; set; } 7 | public string Contact { get; set; } 8 | public string Mail { get; set; } 9 | public string City { get; set; } 10 | public string Country { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Customers/CustomerService.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Customers; 2 | using Northwind.Framework.Domain; 3 | using Northwind.Framework.Helpers; 4 | 5 | namespace Northwind.Application.Customers 6 | { 7 | public class CustomerService : IDomainService 8 | { 9 | private readonly ICustomerRepository _repo; 10 | private readonly IUnitOfWork _unitOfWork; 11 | 12 | public CustomerService(ICustomerRepository repo, IUnitOfWork unitOfWork) 13 | { 14 | _repo = repo; 15 | _unitOfWork = unitOfWork; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Database/NorthwindDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Northwind.Domain.Categories; 3 | using Northwind.Domain.Customers; 4 | using Northwind.Domain.Employees; 5 | using Northwind.Domain.OrderDetails; 6 | using Northwind.Domain.Orders; 7 | using Northwind.Domain.Products; 8 | using Northwind.Domain.Suppliers; 9 | 10 | namespace Northwind.Application.Database 11 | { 12 | public class NorthwindDbContext : DbContext 13 | { 14 | public NorthwindDbContext(DbContextOptions dbContextOptions) : base(dbContextOptions) 15 | { 16 | 17 | } 18 | protected override void OnModelCreating(ModelBuilder modelBuilder) 19 | { 20 | modelBuilder.Entity(e => { 21 | e.HasKey(x => x.Id); 22 | e.Property(x => x.EmployeeId).IsRequired(); 23 | e.HasOne() 24 | .WithMany() 25 | .HasForeignKey(x => x.EmployeeId); 26 | }); 27 | 28 | modelBuilder.Entity(e => { 29 | e.HasKey(x => x.Id); 30 | e.Property(x => x.OrderId).IsRequired(); 31 | e.Property(x => x.ProductId).IsRequired(); 32 | e.HasOne() 33 | .WithMany() 34 | .HasForeignKey(x => x.OrderId); 35 | e.HasOne() 36 | .WithMany() 37 | .HasForeignKey(x => x.ProductId); 38 | }); 39 | 40 | base.OnModelCreating(modelBuilder); 41 | } 42 | public DbSet Employees { get; set; } 43 | public DbSet Customers { get; set; } 44 | public DbSet Orders { get; set; } 45 | public DbSet Products { get; set; } 46 | public DbSet Categories { get; set; } 47 | public DbSet OrderDetails { get; set; } 48 | public DbSet Suppliers { get; set; } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Database/UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore.Storage; 3 | using Northwind.Framework.Entity; 4 | using Northwind.Framework.Helpers; 5 | using System; 6 | 7 | namespace Northwind.Application.Database 8 | { 9 | public class UnitOfWork : IUnitOfWork 10 | { 11 | private readonly DbContext _context; 12 | private IDbContextTransaction _transaction; 13 | public UnitOfWork(DbContext context) 14 | { 15 | _context = context; 16 | } 17 | public DbSet GetDbSet() where T : EntityBase 18 | { 19 | return _context.Set(); 20 | } 21 | public void Commit() 22 | { 23 | using(_transaction = _context.Database.BeginTransaction()) 24 | { 25 | _context.SaveChanges(); 26 | _transaction.Commit(); 27 | } 28 | } 29 | 30 | public void Dispose() 31 | { 32 | _context.Dispose(); 33 | if (_transaction != null) 34 | _transaction.Dispose(); 35 | GC.SuppressFinalize(_context); 36 | GC.SuppressFinalize(this); 37 | GC.Collect(); 38 | } 39 | 40 | public void Rollback() 41 | { 42 | if(_transaction != null) 43 | { 44 | _transaction.Rollback(); 45 | _transaction.Dispose(); 46 | } 47 | } 48 | 49 | ~UnitOfWork() 50 | { 51 | Dispose(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Employees/EmployeeDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Northwind.Application.Employees 4 | { 5 | public class EmployeeDto 6 | { 7 | public int Id { get; set; } 8 | public string FirstName { get; set; } 9 | public string LastName { get; set; } 10 | public string City { get; set; } 11 | public string Country { get; set; } 12 | public DateTime? HireDate { get; set; } 13 | public DateTime? BirthDate { get; set; } 14 | public string EMail { get; set; } 15 | public int? ManagerId { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Employees/EmployeeManager.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Employees; 2 | using Northwind.Domain.Employees; 3 | using Northwind.Framework.Domain; 4 | using Northwind.Framework.Helpers; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using Northwind.Application.Mappers; 8 | 9 | namespace Northwind.Application.Services 10 | { 11 | public class EmployeeManager : IDomainService 12 | { 13 | private readonly IEmployeeRepository _repo; 14 | private readonly IUnitOfWork _unitOfWork; 15 | 16 | public EmployeeManager(IEmployeeRepository repo, IUnitOfWork unitOfWork) 17 | { 18 | _repo = repo; 19 | _unitOfWork = unitOfWork; 20 | } 21 | 22 | public EmployeeDto GetEmployeeById(int id) 23 | { 24 | return _repo.FindById(id).ToDto(); 25 | } 26 | 27 | public bool AddEmployee(EmployeeDto employee) 28 | { 29 | var entity = employee.ToEntity(); 30 | _repo.Save(entity); 31 | return entity.Id > 0; 32 | } 33 | 34 | public IEnumerable GetEmployeesByCountry(string country) 35 | { 36 | return _repo.GetEmployeesByCountry(country).Select(i => i.ToDto()).ToList(); 37 | } 38 | 39 | public bool UserHasManager(int id) 40 | { 41 | var employee = _repo.FindById(id); 42 | var filter = new HasManagerFilter(); 43 | return filter.IsFilteredBy(employee); 44 | } 45 | 46 | public IEnumerable GetEmployeesWithoutManager() 47 | { 48 | var filter = new HasNoManagerFilter(); 49 | return _repo.Find(filter).Select(i => i.ToDto()); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Employees/EmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Employees; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore; 4 | using Northwind.Framework.Helpers; 5 | using System.Linq; 6 | using Northwind.Framework.Domain.Exceptions; 7 | using Northwind.Framework; 8 | 9 | namespace Northwind.Application.Employees 10 | { 11 | internal class EmployeeRepository : IEmployeeRepository 12 | { 13 | private readonly IUnitOfWork _unitOfwork; 14 | public EmployeeRepository(IUnitOfWork unitOfwork) 15 | { 16 | _unitOfwork = unitOfwork; 17 | } 18 | public DbSet Repository => _unitOfwork.GetDbSet(); 19 | 20 | public IEnumerable Find(IFilter filter) 21 | { 22 | return Repository.Where(filter.FilterExpression).ToList(); 23 | } 24 | 25 | public Employee FindById(int id) 26 | { 27 | var employee = Repository.FirstOrDefault(i => i.Id == id); 28 | if (employee == null) 29 | { 30 | throw new NotFoundByIdException(); 31 | } 32 | return employee; 33 | } 34 | 35 | public Employee FindSingle(IFilter spec) 36 | { 37 | return Repository.Where(spec.FilterExpression).SingleOrDefault(); 38 | } 39 | 40 | public IEnumerable GetEmployeesByCountry(string countryName) 41 | { 42 | return Repository.Where(i => i.Country == countryName).ToList(); 43 | } 44 | 45 | public Employee GetManager(int employeeId) 46 | { 47 | var employee = FindById(employeeId); 48 | if (TypeCheck.IsUsableAsId(employee.ManagerId)) 49 | { 50 | var manager = FindById(employee.ManagerId.Value); 51 | return manager; 52 | } 53 | return null; 54 | } 55 | 56 | public void Remove(Employee entity) 57 | { 58 | Repository.Remove(entity); 59 | } 60 | 61 | public void Save(Employee entity) 62 | { 63 | Repository.Add(entity); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/ExtensionRegistery.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.DependencyInjection; 3 | using Northwind.Application.Categories; 4 | using Northwind.Application.Database; 5 | using Northwind.Application.Employees; 6 | using Northwind.Application.Products; 7 | using Northwind.Application.Services; 8 | using Northwind.Domain.Categories; 9 | using Northwind.Domain.Employees; 10 | using Northwind.Domain.Products; 11 | using Northwind.Framework.Helpers; 12 | 13 | namespace Northwind.Application 14 | { 15 | public static class ExtensionRegistery 16 | { 17 | public static void AddNorthwind(this IServiceCollection serviceCollection) 18 | { 19 | serviceCollection.AddScoped(); 20 | serviceCollection.AddScoped(); 21 | serviceCollection.AddScoped(); 22 | serviceCollection.AddScoped(); 23 | serviceCollection.AddScoped(); 24 | serviceCollection.AddScoped(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Mappers/CategoryMapper.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Categories; 2 | using Northwind.Domain.Categories; 3 | 4 | namespace Northwind.Application.Mappers 5 | { 6 | public static class CategoryMapper 7 | { 8 | public static CategoryDto ToDto(this Category entity) 9 | { 10 | var dto = new CategoryDto 11 | { 12 | Id = entity.Id, 13 | Name = entity.Name, 14 | Decription = entity.Description 15 | }; 16 | return dto; 17 | } 18 | 19 | public static Category ToEntity(this CategoryDto dto) 20 | { 21 | var category = Category.Create(dto.Name, dto.Decription); 22 | category.SetId(dto.Id); 23 | return category; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Mappers/EmployeeMapper.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Employees; 2 | using Northwind.Domain.Employees; 3 | 4 | namespace Northwind.Application.Mappers 5 | { 6 | public static class EmployeeMapper 7 | { 8 | public static EmployeeDto ToDto(this Employee entity) 9 | { 10 | var dto = new EmployeeDto 11 | { 12 | Id = entity.Id, 13 | FirstName = entity.FirstName, 14 | LastName = entity.LastName, 15 | EMail = entity.EMail, 16 | Country = entity.Country, 17 | City = entity.City, 18 | HireDate = entity.HireDate, 19 | ManagerId = entity.ManagerId, 20 | BirthDate = entity.BirthDate 21 | }; 22 | return dto; 23 | } 24 | 25 | public static Employee ToEntity(this EmployeeDto dto) 26 | { 27 | var employee = Employee.Create(dto.FirstName, dto.LastName,dto.EMail); 28 | employee.SetId(dto.Id); 29 | employee.BirthDate = dto.BirthDate; 30 | employee.Country = dto.Country; 31 | employee.City = dto.City; 32 | employee.HireDate = dto.HireDate; 33 | return employee; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Mappers/ProductMapper.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Products; 2 | using Northwind.Domain.Products; 3 | 4 | namespace Northwind.Application.Mappers 5 | { 6 | public static class ProductMapper 7 | { 8 | public static ProductDto ToDto(this Product entity) 9 | { 10 | var dto = new ProductDto 11 | { 12 | Id = entity.Id, 13 | ProductName = entity.Name, 14 | Price = entity.UnitPrice, 15 | UnitsInStock = entity.UnitsInStock, 16 | CategoryId = entity.CategoryId, 17 | SupplierId = entity.SupplierId 18 | }; 19 | return dto; 20 | } 21 | 22 | public static Product ToEntity(this ProductDto dto) 23 | { 24 | var product = Product.CreateSimple(dto.ProductName, dto.Price, dto.UnitsInStock); 25 | product.SetId(dto.Id); 26 | return product; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101075051_CreateDatabase.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171101075051_CreateDatabase")] 15 | partial class CreateDatabase 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("CustomerId"); 106 | 107 | b.Property("EmployeeId"); 108 | 109 | b.Property("IsUrgent"); 110 | 111 | b.Property("LastShipDate"); 112 | 113 | b.Property("Modified"); 114 | 115 | b.HasKey("Id"); 116 | 117 | b.HasIndex("CustomerId"); 118 | 119 | b.ToTable("Orders"); 120 | }); 121 | 122 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 123 | { 124 | b.Property("Id") 125 | .ValueGeneratedOnAdd(); 126 | 127 | b.Property("CategoryId"); 128 | 129 | b.Property("Created"); 130 | 131 | b.Property("Modified"); 132 | 133 | b.Property("Name"); 134 | 135 | b.Property("SupplierId"); 136 | 137 | b.Property("UnitPrice"); 138 | 139 | b.Property("UnitsInStock"); 140 | 141 | b.HasKey("Id"); 142 | 143 | b.HasIndex("CategoryId"); 144 | 145 | b.ToTable("Products"); 146 | }); 147 | 148 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 149 | { 150 | b.HasOne("Northwind.Domain.Customers.Customer") 151 | .WithMany("Orders") 152 | .HasForeignKey("CustomerId"); 153 | }); 154 | 155 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 156 | { 157 | b.HasOne("Northwind.Domain.Categories.Category") 158 | .WithMany("Products") 159 | .HasForeignKey("CategoryId") 160 | .OnDelete(DeleteBehavior.Cascade); 161 | }); 162 | #pragma warning restore 612, 618 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101075051_CreateDatabase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Northwind.Application.Migrations 7 | { 8 | public partial class CreateDatabase : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Categories", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "int", nullable: false) 17 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 18 | Created = table.Column(type: "datetime2", nullable: false), 19 | Description = table.Column(type: "nvarchar(max)", nullable: true), 20 | Modified = table.Column(type: "datetime2", nullable: false), 21 | Name = table.Column(type: "nvarchar(max)", nullable: true) 22 | }, 23 | constraints: table => 24 | { 25 | table.PrimaryKey("PK_Categories", x => x.Id); 26 | }); 27 | 28 | migrationBuilder.CreateTable( 29 | name: "Customers", 30 | columns: table => new 31 | { 32 | Id = table.Column(type: "nvarchar(450)", nullable: false), 33 | City = table.Column(type: "nvarchar(max)", nullable: true), 34 | Contact = table.Column(type: "nvarchar(max)", nullable: true), 35 | ContactEMail = table.Column(type: "nvarchar(max)", nullable: true), 36 | Country = table.Column(type: "nvarchar(max)", nullable: true), 37 | Created = table.Column(type: "datetime2", nullable: false), 38 | CustomerId = table.Column(type: "nvarchar(max)", nullable: true), 39 | Modified = table.Column(type: "datetime2", nullable: false), 40 | Title = table.Column(type: "nvarchar(max)", nullable: true) 41 | }, 42 | constraints: table => 43 | { 44 | table.PrimaryKey("PK_Customers", x => x.Id); 45 | }); 46 | 47 | migrationBuilder.CreateTable( 48 | name: "Employees", 49 | columns: table => new 50 | { 51 | Id = table.Column(type: "int", nullable: false) 52 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 53 | BirthDate = table.Column(type: "datetime2", nullable: true), 54 | City = table.Column(type: "nvarchar(max)", nullable: true), 55 | Country = table.Column(type: "nvarchar(max)", nullable: true), 56 | Created = table.Column(type: "datetime2", nullable: false), 57 | EMail = table.Column(type: "nvarchar(max)", nullable: true), 58 | FirstName = table.Column(type: "nvarchar(max)", nullable: true), 59 | HireDate = table.Column(type: "datetime2", nullable: true), 60 | LastName = table.Column(type: "nvarchar(max)", nullable: true), 61 | ManagerId = table.Column(type: "bigint", nullable: false), 62 | Modified = table.Column(type: "datetime2", nullable: false) 63 | }, 64 | constraints: table => 65 | { 66 | table.PrimaryKey("PK_Employees", x => x.Id); 67 | }); 68 | 69 | migrationBuilder.CreateTable( 70 | name: "Products", 71 | columns: table => new 72 | { 73 | Id = table.Column(type: "bigint", nullable: false) 74 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 75 | CategoryId = table.Column(type: "int", nullable: false), 76 | Created = table.Column(type: "datetime2", nullable: false), 77 | Modified = table.Column(type: "datetime2", nullable: false), 78 | Name = table.Column(type: "nvarchar(max)", nullable: true), 79 | SupplierId = table.Column(type: "int", nullable: false), 80 | UnitPrice = table.Column(type: "decimal(18, 2)", nullable: false), 81 | UnitsInStock = table.Column(type: "float", nullable: false) 82 | }, 83 | constraints: table => 84 | { 85 | table.PrimaryKey("PK_Products", x => x.Id); 86 | table.ForeignKey( 87 | name: "FK_Products_Categories_CategoryId", 88 | column: x => x.CategoryId, 89 | principalTable: "Categories", 90 | principalColumn: "Id", 91 | onDelete: ReferentialAction.Cascade); 92 | }); 93 | 94 | migrationBuilder.CreateTable( 95 | name: "Orders", 96 | columns: table => new 97 | { 98 | Id = table.Column(type: "bigint", nullable: false) 99 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 100 | Created = table.Column(type: "datetime2", nullable: false), 101 | CustomerId = table.Column(type: "nvarchar(450)", nullable: true), 102 | EmployeeId = table.Column(type: "int", nullable: false), 103 | IsUrgent = table.Column(type: "bit", nullable: false), 104 | LastShipDate = table.Column(type: "datetime2", nullable: true), 105 | Modified = table.Column(type: "datetime2", nullable: false) 106 | }, 107 | constraints: table => 108 | { 109 | table.PrimaryKey("PK_Orders", x => x.Id); 110 | table.ForeignKey( 111 | name: "FK_Orders_Customers_CustomerId", 112 | column: x => x.CustomerId, 113 | principalTable: "Customers", 114 | principalColumn: "Id", 115 | onDelete: ReferentialAction.Restrict); 116 | }); 117 | 118 | migrationBuilder.CreateIndex( 119 | name: "IX_Orders_CustomerId", 120 | table: "Orders", 121 | column: "CustomerId"); 122 | 123 | migrationBuilder.CreateIndex( 124 | name: "IX_Products_CategoryId", 125 | table: "Products", 126 | column: "CategoryId"); 127 | } 128 | 129 | protected override void Down(MigrationBuilder migrationBuilder) 130 | { 131 | migrationBuilder.DropTable( 132 | name: "Employees"); 133 | 134 | migrationBuilder.DropTable( 135 | name: "Orders"); 136 | 137 | migrationBuilder.DropTable( 138 | name: "Products"); 139 | 140 | migrationBuilder.DropTable( 141 | name: "Customers"); 142 | 143 | migrationBuilder.DropTable( 144 | name: "Categories"); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101081850_OrderRelation.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171101081850_OrderRelation")] 15 | partial class OrderRelation 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("CustomerId"); 106 | 107 | b.Property("EmployeeId"); 108 | 109 | b.Property("IsUrgent"); 110 | 111 | b.Property("LastShipDate"); 112 | 113 | b.Property("Modified"); 114 | 115 | b.HasKey("Id"); 116 | 117 | b.HasIndex("CustomerId"); 118 | 119 | b.HasIndex("EmployeeId"); 120 | 121 | b.ToTable("Orders"); 122 | }); 123 | 124 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 125 | { 126 | b.Property("Id") 127 | .ValueGeneratedOnAdd(); 128 | 129 | b.Property("CategoryId"); 130 | 131 | b.Property("Created"); 132 | 133 | b.Property("Modified"); 134 | 135 | b.Property("Name"); 136 | 137 | b.Property("SupplierId"); 138 | 139 | b.Property("UnitPrice"); 140 | 141 | b.Property("UnitsInStock"); 142 | 143 | b.HasKey("Id"); 144 | 145 | b.HasIndex("CategoryId"); 146 | 147 | b.ToTable("Products"); 148 | }); 149 | 150 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 151 | { 152 | b.HasOne("Northwind.Domain.Customers.Customer") 153 | .WithMany("Orders") 154 | .HasForeignKey("CustomerId"); 155 | 156 | b.HasOne("Northwind.Domain.Employees.Employee") 157 | .WithMany() 158 | .HasForeignKey("EmployeeId") 159 | .OnDelete(DeleteBehavior.Cascade); 160 | }); 161 | 162 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 163 | { 164 | b.HasOne("Northwind.Domain.Categories.Category") 165 | .WithMany("Products") 166 | .HasForeignKey("CategoryId") 167 | .OnDelete(DeleteBehavior.Cascade); 168 | }); 169 | #pragma warning restore 612, 618 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101081850_OrderRelation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.Application.Migrations 6 | { 7 | public partial class OrderRelation : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateIndex( 12 | name: "IX_Orders_EmployeeId", 13 | table: "Orders", 14 | column: "EmployeeId"); 15 | 16 | migrationBuilder.AddForeignKey( 17 | name: "FK_Orders_Employees_EmployeeId", 18 | table: "Orders", 19 | column: "EmployeeId", 20 | principalTable: "Employees", 21 | principalColumn: "Id", 22 | onDelete: ReferentialAction.Cascade); 23 | } 24 | 25 | protected override void Down(MigrationBuilder migrationBuilder) 26 | { 27 | migrationBuilder.DropForeignKey( 28 | name: "FK_Orders_Employees_EmployeeId", 29 | table: "Orders"); 30 | 31 | migrationBuilder.DropIndex( 32 | name: "IX_Orders_EmployeeId", 33 | table: "Orders"); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101084922_OrderDetailsAndRelation.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171101084922_OrderDetailsAndRelation")] 15 | partial class OrderDetailsAndRelation 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("Discount"); 106 | 107 | b.Property("Modified"); 108 | 109 | b.Property("OrderId"); 110 | 111 | b.Property("Price"); 112 | 113 | b.Property("ProductId"); 114 | 115 | b.Property("Quantity"); 116 | 117 | b.HasKey("Id"); 118 | 119 | b.HasIndex("OrderId"); 120 | 121 | b.HasIndex("ProductId"); 122 | 123 | b.ToTable("OrderDetails"); 124 | }); 125 | 126 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 127 | { 128 | b.Property("Id") 129 | .ValueGeneratedOnAdd(); 130 | 131 | b.Property("Created"); 132 | 133 | b.Property("CustomerId"); 134 | 135 | b.Property("EmployeeId"); 136 | 137 | b.Property("IsUrgent"); 138 | 139 | b.Property("LastShipDate"); 140 | 141 | b.Property("Modified"); 142 | 143 | b.HasKey("Id"); 144 | 145 | b.HasIndex("CustomerId"); 146 | 147 | b.HasIndex("EmployeeId"); 148 | 149 | b.ToTable("Orders"); 150 | }); 151 | 152 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 153 | { 154 | b.Property("Id") 155 | .ValueGeneratedOnAdd(); 156 | 157 | b.Property("CategoryId"); 158 | 159 | b.Property("Created"); 160 | 161 | b.Property("Modified"); 162 | 163 | b.Property("Name"); 164 | 165 | b.Property("SupplierId"); 166 | 167 | b.Property("UnitPrice"); 168 | 169 | b.Property("UnitsInStock"); 170 | 171 | b.HasKey("Id"); 172 | 173 | b.HasIndex("CategoryId"); 174 | 175 | b.ToTable("Products"); 176 | }); 177 | 178 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 179 | { 180 | b.HasOne("Northwind.Domain.Orders.Order") 181 | .WithMany() 182 | .HasForeignKey("OrderId") 183 | .OnDelete(DeleteBehavior.Cascade); 184 | 185 | b.HasOne("Northwind.Domain.Products.Product") 186 | .WithMany() 187 | .HasForeignKey("ProductId") 188 | .OnDelete(DeleteBehavior.Cascade); 189 | }); 190 | 191 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 192 | { 193 | b.HasOne("Northwind.Domain.Customers.Customer") 194 | .WithMany("Orders") 195 | .HasForeignKey("CustomerId"); 196 | 197 | b.HasOne("Northwind.Domain.Employees.Employee") 198 | .WithMany() 199 | .HasForeignKey("EmployeeId") 200 | .OnDelete(DeleteBehavior.Cascade); 201 | }); 202 | 203 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 204 | { 205 | b.HasOne("Northwind.Domain.Categories.Category") 206 | .WithMany("Products") 207 | .HasForeignKey("CategoryId") 208 | .OnDelete(DeleteBehavior.Cascade); 209 | }); 210 | #pragma warning restore 612, 618 211 | } 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101084922_OrderDetailsAndRelation.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Northwind.Application.Migrations 7 | { 8 | public partial class OrderDetailsAndRelation : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "OrderDetails", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "bigint", nullable: false) 17 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 18 | Created = table.Column(type: "datetime2", nullable: false), 19 | Discount = table.Column(type: "float", nullable: false), 20 | Modified = table.Column(type: "datetime2", nullable: false), 21 | OrderId = table.Column(type: "bigint", nullable: false), 22 | Price = table.Column(type: "float", nullable: false), 23 | ProductId = table.Column(type: "bigint", nullable: false), 24 | Quantity = table.Column(type: "float", nullable: false) 25 | }, 26 | constraints: table => 27 | { 28 | table.PrimaryKey("PK_OrderDetails", x => x.Id); 29 | table.ForeignKey( 30 | name: "FK_OrderDetails_Orders_OrderId", 31 | column: x => x.OrderId, 32 | principalTable: "Orders", 33 | principalColumn: "Id", 34 | onDelete: ReferentialAction.Cascade); 35 | table.ForeignKey( 36 | name: "FK_OrderDetails_Products_ProductId", 37 | column: x => x.ProductId, 38 | principalTable: "Products", 39 | principalColumn: "Id", 40 | onDelete: ReferentialAction.Cascade); 41 | }); 42 | 43 | migrationBuilder.CreateIndex( 44 | name: "IX_OrderDetails_OrderId", 45 | table: "OrderDetails", 46 | column: "OrderId"); 47 | 48 | migrationBuilder.CreateIndex( 49 | name: "IX_OrderDetails_ProductId", 50 | table: "OrderDetails", 51 | column: "ProductId"); 52 | } 53 | 54 | protected override void Down(MigrationBuilder migrationBuilder) 55 | { 56 | migrationBuilder.DropTable( 57 | name: "OrderDetails"); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101085136_SuppliersMigration.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171101085136_SuppliersMigration")] 15 | partial class SuppliersMigration 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("Discount"); 106 | 107 | b.Property("Modified"); 108 | 109 | b.Property("OrderId"); 110 | 111 | b.Property("Price"); 112 | 113 | b.Property("ProductId"); 114 | 115 | b.Property("Quantity"); 116 | 117 | b.HasKey("Id"); 118 | 119 | b.HasIndex("OrderId"); 120 | 121 | b.HasIndex("ProductId"); 122 | 123 | b.ToTable("OrderDetails"); 124 | }); 125 | 126 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 127 | { 128 | b.Property("Id") 129 | .ValueGeneratedOnAdd(); 130 | 131 | b.Property("Created"); 132 | 133 | b.Property("CustomerId"); 134 | 135 | b.Property("EmployeeId"); 136 | 137 | b.Property("IsUrgent"); 138 | 139 | b.Property("LastShipDate"); 140 | 141 | b.Property("Modified"); 142 | 143 | b.HasKey("Id"); 144 | 145 | b.HasIndex("CustomerId"); 146 | 147 | b.HasIndex("EmployeeId"); 148 | 149 | b.ToTable("Orders"); 150 | }); 151 | 152 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 153 | { 154 | b.Property("Id") 155 | .ValueGeneratedOnAdd(); 156 | 157 | b.Property("CategoryId"); 158 | 159 | b.Property("Created"); 160 | 161 | b.Property("Modified"); 162 | 163 | b.Property("Name"); 164 | 165 | b.Property("SupplierId"); 166 | 167 | b.Property("SupplierId1"); 168 | 169 | b.Property("UnitPrice"); 170 | 171 | b.Property("UnitsInStock"); 172 | 173 | b.HasKey("Id"); 174 | 175 | b.HasIndex("CategoryId"); 176 | 177 | b.HasIndex("SupplierId"); 178 | 179 | b.HasIndex("SupplierId1"); 180 | 181 | b.ToTable("Products"); 182 | }); 183 | 184 | modelBuilder.Entity("Northwind.Domain.Suppliers.Supplier", b => 185 | { 186 | b.Property("Id") 187 | .ValueGeneratedOnAdd(); 188 | 189 | b.Property("City"); 190 | 191 | b.Property("CompanyName"); 192 | 193 | b.Property("Country"); 194 | 195 | b.Property("Created"); 196 | 197 | b.Property("Email"); 198 | 199 | b.Property("Fax"); 200 | 201 | b.Property("Manager"); 202 | 203 | b.Property("Modified"); 204 | 205 | b.Property("Phone"); 206 | 207 | b.HasKey("Id"); 208 | 209 | b.ToTable("Suppliers"); 210 | }); 211 | 212 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 213 | { 214 | b.HasOne("Northwind.Domain.Orders.Order") 215 | .WithMany() 216 | .HasForeignKey("OrderId") 217 | .OnDelete(DeleteBehavior.Cascade); 218 | 219 | b.HasOne("Northwind.Domain.Products.Product") 220 | .WithMany() 221 | .HasForeignKey("ProductId") 222 | .OnDelete(DeleteBehavior.Cascade); 223 | }); 224 | 225 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 226 | { 227 | b.HasOne("Northwind.Domain.Customers.Customer") 228 | .WithMany("Orders") 229 | .HasForeignKey("CustomerId"); 230 | 231 | b.HasOne("Northwind.Domain.Employees.Employee") 232 | .WithMany() 233 | .HasForeignKey("EmployeeId") 234 | .OnDelete(DeleteBehavior.Cascade); 235 | }); 236 | 237 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 238 | { 239 | b.HasOne("Northwind.Domain.Categories.Category") 240 | .WithMany("Products") 241 | .HasForeignKey("CategoryId") 242 | .OnDelete(DeleteBehavior.Cascade); 243 | 244 | b.HasOne("Northwind.Domain.Suppliers.Supplier") 245 | .WithMany() 246 | .HasForeignKey("SupplierId") 247 | .OnDelete(DeleteBehavior.Cascade); 248 | 249 | b.HasOne("Northwind.Domain.Suppliers.Supplier") 250 | .WithMany("Products") 251 | .HasForeignKey("SupplierId1"); 252 | }); 253 | #pragma warning restore 612, 618 254 | } 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101085136_SuppliersMigration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Northwind.Application.Migrations 7 | { 8 | public partial class SuppliersMigration : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.AddColumn( 13 | name: "SupplierId1", 14 | table: "Products", 15 | type: "int", 16 | nullable: true); 17 | 18 | migrationBuilder.CreateTable( 19 | name: "Suppliers", 20 | columns: table => new 21 | { 22 | Id = table.Column(type: "int", nullable: false) 23 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 24 | City = table.Column(type: "nvarchar(max)", nullable: true), 25 | CompanyName = table.Column(type: "nvarchar(max)", nullable: true), 26 | Country = table.Column(type: "nvarchar(max)", nullable: true), 27 | Created = table.Column(type: "datetime2", nullable: false), 28 | Email = table.Column(type: "nvarchar(max)", nullable: true), 29 | Fax = table.Column(type: "nvarchar(max)", nullable: true), 30 | Manager = table.Column(type: "nvarchar(max)", nullable: true), 31 | Modified = table.Column(type: "datetime2", nullable: false), 32 | Phone = table.Column(type: "nvarchar(max)", nullable: true) 33 | }, 34 | constraints: table => 35 | { 36 | table.PrimaryKey("PK_Suppliers", x => x.Id); 37 | }); 38 | 39 | migrationBuilder.CreateIndex( 40 | name: "IX_Products_SupplierId", 41 | table: "Products", 42 | column: "SupplierId"); 43 | 44 | migrationBuilder.CreateIndex( 45 | name: "IX_Products_SupplierId1", 46 | table: "Products", 47 | column: "SupplierId1"); 48 | 49 | migrationBuilder.AddForeignKey( 50 | name: "FK_Products_Suppliers_SupplierId", 51 | table: "Products", 52 | column: "SupplierId", 53 | principalTable: "Suppliers", 54 | principalColumn: "Id", 55 | onDelete: ReferentialAction.Cascade); 56 | 57 | migrationBuilder.AddForeignKey( 58 | name: "FK_Products_Suppliers_SupplierId1", 59 | table: "Products", 60 | column: "SupplierId1", 61 | principalTable: "Suppliers", 62 | principalColumn: "Id", 63 | onDelete: ReferentialAction.Restrict); 64 | } 65 | 66 | protected override void Down(MigrationBuilder migrationBuilder) 67 | { 68 | migrationBuilder.DropForeignKey( 69 | name: "FK_Products_Suppliers_SupplierId", 70 | table: "Products"); 71 | 72 | migrationBuilder.DropForeignKey( 73 | name: "FK_Products_Suppliers_SupplierId1", 74 | table: "Products"); 75 | 76 | migrationBuilder.DropTable( 77 | name: "Suppliers"); 78 | 79 | migrationBuilder.DropIndex( 80 | name: "IX_Products_SupplierId", 81 | table: "Products"); 82 | 83 | migrationBuilder.DropIndex( 84 | name: "IX_Products_SupplierId1", 85 | table: "Products"); 86 | 87 | migrationBuilder.DropColumn( 88 | name: "SupplierId1", 89 | table: "Products"); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101085257_SuppliersMigrationRollback.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171101085257_SuppliersMigrationRollback")] 15 | partial class SuppliersMigrationRollback 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("Discount"); 106 | 107 | b.Property("Modified"); 108 | 109 | b.Property("OrderId"); 110 | 111 | b.Property("Price"); 112 | 113 | b.Property("ProductId"); 114 | 115 | b.Property("Quantity"); 116 | 117 | b.HasKey("Id"); 118 | 119 | b.HasIndex("OrderId"); 120 | 121 | b.HasIndex("ProductId"); 122 | 123 | b.ToTable("OrderDetails"); 124 | }); 125 | 126 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 127 | { 128 | b.Property("Id") 129 | .ValueGeneratedOnAdd(); 130 | 131 | b.Property("Created"); 132 | 133 | b.Property("CustomerId"); 134 | 135 | b.Property("EmployeeId"); 136 | 137 | b.Property("IsUrgent"); 138 | 139 | b.Property("LastShipDate"); 140 | 141 | b.Property("Modified"); 142 | 143 | b.HasKey("Id"); 144 | 145 | b.HasIndex("CustomerId"); 146 | 147 | b.HasIndex("EmployeeId"); 148 | 149 | b.ToTable("Orders"); 150 | }); 151 | 152 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 153 | { 154 | b.Property("Id") 155 | .ValueGeneratedOnAdd(); 156 | 157 | b.Property("CategoryId"); 158 | 159 | b.Property("Created"); 160 | 161 | b.Property("Modified"); 162 | 163 | b.Property("Name"); 164 | 165 | b.Property("SupplierId"); 166 | 167 | b.Property("UnitPrice"); 168 | 169 | b.Property("UnitsInStock"); 170 | 171 | b.HasKey("Id"); 172 | 173 | b.HasIndex("CategoryId"); 174 | 175 | b.HasIndex("SupplierId"); 176 | 177 | b.ToTable("Products"); 178 | }); 179 | 180 | modelBuilder.Entity("Northwind.Domain.Suppliers.Supplier", b => 181 | { 182 | b.Property("Id") 183 | .ValueGeneratedOnAdd(); 184 | 185 | b.Property("City"); 186 | 187 | b.Property("CompanyName"); 188 | 189 | b.Property("Country"); 190 | 191 | b.Property("Created"); 192 | 193 | b.Property("Email"); 194 | 195 | b.Property("Fax"); 196 | 197 | b.Property("Manager"); 198 | 199 | b.Property("Modified"); 200 | 201 | b.Property("Phone"); 202 | 203 | b.HasKey("Id"); 204 | 205 | b.ToTable("Suppliers"); 206 | }); 207 | 208 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 209 | { 210 | b.HasOne("Northwind.Domain.Orders.Order") 211 | .WithMany() 212 | .HasForeignKey("OrderId") 213 | .OnDelete(DeleteBehavior.Cascade); 214 | 215 | b.HasOne("Northwind.Domain.Products.Product") 216 | .WithMany() 217 | .HasForeignKey("ProductId") 218 | .OnDelete(DeleteBehavior.Cascade); 219 | }); 220 | 221 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 222 | { 223 | b.HasOne("Northwind.Domain.Customers.Customer") 224 | .WithMany("Orders") 225 | .HasForeignKey("CustomerId"); 226 | 227 | b.HasOne("Northwind.Domain.Employees.Employee") 228 | .WithMany() 229 | .HasForeignKey("EmployeeId") 230 | .OnDelete(DeleteBehavior.Cascade); 231 | }); 232 | 233 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 234 | { 235 | b.HasOne("Northwind.Domain.Categories.Category") 236 | .WithMany("Products") 237 | .HasForeignKey("CategoryId") 238 | .OnDelete(DeleteBehavior.Cascade); 239 | 240 | b.HasOne("Northwind.Domain.Suppliers.Supplier") 241 | .WithMany("Products") 242 | .HasForeignKey("SupplierId") 243 | .OnDelete(DeleteBehavior.Cascade); 244 | }); 245 | #pragma warning restore 612, 618 246 | } 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171101085257_SuppliersMigrationRollback.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.Application.Migrations 6 | { 7 | public partial class SuppliersMigrationRollback : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.DropForeignKey( 12 | name: "FK_Products_Suppliers_SupplierId1", 13 | table: "Products"); 14 | 15 | migrationBuilder.DropIndex( 16 | name: "IX_Products_SupplierId1", 17 | table: "Products"); 18 | 19 | migrationBuilder.DropColumn( 20 | name: "SupplierId1", 21 | table: "Products"); 22 | } 23 | 24 | protected override void Down(MigrationBuilder migrationBuilder) 25 | { 26 | migrationBuilder.AddColumn( 27 | name: "SupplierId1", 28 | table: "Products", 29 | nullable: true); 30 | 31 | migrationBuilder.CreateIndex( 32 | name: "IX_Products_SupplierId1", 33 | table: "Products", 34 | column: "SupplierId1"); 35 | 36 | migrationBuilder.AddForeignKey( 37 | name: "FK_Products_Suppliers_SupplierId1", 38 | table: "Products", 39 | column: "SupplierId1", 40 | principalTable: "Suppliers", 41 | principalColumn: "Id", 42 | onDelete: ReferentialAction.Restrict); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171108132241_EmployeeManagerId.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | [Migration("20171108132241_EmployeeManagerId")] 15 | partial class EmployeeManagerId 16 | { 17 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 18 | { 19 | #pragma warning disable 612, 618 20 | modelBuilder 21 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 22 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 23 | 24 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 25 | { 26 | b.Property("Id") 27 | .ValueGeneratedOnAdd(); 28 | 29 | b.Property("Created"); 30 | 31 | b.Property("Description"); 32 | 33 | b.Property("Modified"); 34 | 35 | b.Property("Name"); 36 | 37 | b.HasKey("Id"); 38 | 39 | b.ToTable("Categories"); 40 | }); 41 | 42 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 43 | { 44 | b.Property("Id") 45 | .ValueGeneratedOnAdd(); 46 | 47 | b.Property("City"); 48 | 49 | b.Property("Contact"); 50 | 51 | b.Property("ContactEMail"); 52 | 53 | b.Property("Country"); 54 | 55 | b.Property("Created"); 56 | 57 | b.Property("CustomerId"); 58 | 59 | b.Property("Modified"); 60 | 61 | b.Property("Title"); 62 | 63 | b.HasKey("Id"); 64 | 65 | b.ToTable("Customers"); 66 | }); 67 | 68 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 69 | { 70 | b.Property("Id") 71 | .ValueGeneratedOnAdd(); 72 | 73 | b.Property("BirthDate"); 74 | 75 | b.Property("City"); 76 | 77 | b.Property("Country"); 78 | 79 | b.Property("Created"); 80 | 81 | b.Property("EMail"); 82 | 83 | b.Property("FirstName"); 84 | 85 | b.Property("HireDate"); 86 | 87 | b.Property("LastName"); 88 | 89 | b.Property("ManagerId"); 90 | 91 | b.Property("Modified"); 92 | 93 | b.HasKey("Id"); 94 | 95 | b.ToTable("Employees"); 96 | }); 97 | 98 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 99 | { 100 | b.Property("Id") 101 | .ValueGeneratedOnAdd(); 102 | 103 | b.Property("Created"); 104 | 105 | b.Property("Discount"); 106 | 107 | b.Property("Modified"); 108 | 109 | b.Property("OrderId"); 110 | 111 | b.Property("Price"); 112 | 113 | b.Property("ProductId"); 114 | 115 | b.Property("Quantity"); 116 | 117 | b.HasKey("Id"); 118 | 119 | b.HasIndex("OrderId"); 120 | 121 | b.HasIndex("ProductId"); 122 | 123 | b.ToTable("OrderDetails"); 124 | }); 125 | 126 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 127 | { 128 | b.Property("Id") 129 | .ValueGeneratedOnAdd(); 130 | 131 | b.Property("Created"); 132 | 133 | b.Property("CustomerId"); 134 | 135 | b.Property("EmployeeId"); 136 | 137 | b.Property("IsUrgent"); 138 | 139 | b.Property("LastShipDate"); 140 | 141 | b.Property("Modified"); 142 | 143 | b.HasKey("Id"); 144 | 145 | b.HasIndex("CustomerId"); 146 | 147 | b.HasIndex("EmployeeId"); 148 | 149 | b.ToTable("Orders"); 150 | }); 151 | 152 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 153 | { 154 | b.Property("Id") 155 | .ValueGeneratedOnAdd(); 156 | 157 | b.Property("CategoryId"); 158 | 159 | b.Property("Created"); 160 | 161 | b.Property("Modified"); 162 | 163 | b.Property("Name"); 164 | 165 | b.Property("SupplierId"); 166 | 167 | b.Property("UnitPrice"); 168 | 169 | b.Property("UnitsInStock"); 170 | 171 | b.HasKey("Id"); 172 | 173 | b.HasIndex("CategoryId"); 174 | 175 | b.HasIndex("SupplierId"); 176 | 177 | b.ToTable("Products"); 178 | }); 179 | 180 | modelBuilder.Entity("Northwind.Domain.Suppliers.Supplier", b => 181 | { 182 | b.Property("Id") 183 | .ValueGeneratedOnAdd(); 184 | 185 | b.Property("City"); 186 | 187 | b.Property("CompanyName"); 188 | 189 | b.Property("Country"); 190 | 191 | b.Property("Created"); 192 | 193 | b.Property("Email"); 194 | 195 | b.Property("Fax"); 196 | 197 | b.Property("Manager"); 198 | 199 | b.Property("Modified"); 200 | 201 | b.Property("Phone"); 202 | 203 | b.HasKey("Id"); 204 | 205 | b.ToTable("Suppliers"); 206 | }); 207 | 208 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 209 | { 210 | b.HasOne("Northwind.Domain.Orders.Order") 211 | .WithMany() 212 | .HasForeignKey("OrderId") 213 | .OnDelete(DeleteBehavior.Cascade); 214 | 215 | b.HasOne("Northwind.Domain.Products.Product") 216 | .WithMany() 217 | .HasForeignKey("ProductId") 218 | .OnDelete(DeleteBehavior.Cascade); 219 | }); 220 | 221 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 222 | { 223 | b.HasOne("Northwind.Domain.Customers.Customer") 224 | .WithMany("Orders") 225 | .HasForeignKey("CustomerId"); 226 | 227 | b.HasOne("Northwind.Domain.Employees.Employee") 228 | .WithMany() 229 | .HasForeignKey("EmployeeId") 230 | .OnDelete(DeleteBehavior.Cascade); 231 | }); 232 | 233 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 234 | { 235 | b.HasOne("Northwind.Domain.Categories.Category") 236 | .WithMany("Products") 237 | .HasForeignKey("CategoryId") 238 | .OnDelete(DeleteBehavior.Cascade); 239 | 240 | b.HasOne("Northwind.Domain.Suppliers.Supplier") 241 | .WithMany("Products") 242 | .HasForeignKey("SupplierId") 243 | .OnDelete(DeleteBehavior.Cascade); 244 | }); 245 | #pragma warning restore 612, 618 246 | } 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/20171108132241_EmployeeManagerId.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.Application.Migrations 6 | { 7 | public partial class EmployeeManagerId : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.AlterColumn( 12 | name: "ManagerId", 13 | table: "Employees", 14 | type: "bigint", 15 | nullable: true, 16 | oldClrType: typeof(long)); 17 | } 18 | 19 | protected override void Down(MigrationBuilder migrationBuilder) 20 | { 21 | migrationBuilder.AlterColumn( 22 | name: "ManagerId", 23 | table: "Employees", 24 | nullable: false, 25 | oldClrType: typeof(long), 26 | oldType: "bigint", 27 | oldNullable: true); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Migrations/NorthwindDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Infrastructure; 4 | using Microsoft.EntityFrameworkCore.Metadata; 5 | using Microsoft.EntityFrameworkCore.Migrations; 6 | using Microsoft.EntityFrameworkCore.Storage; 7 | using Microsoft.EntityFrameworkCore.Storage.Internal; 8 | using Northwind.Application.Database; 9 | using System; 10 | 11 | namespace Northwind.Application.Migrations 12 | { 13 | [DbContext(typeof(NorthwindDbContext))] 14 | partial class NorthwindDbContextModelSnapshot : ModelSnapshot 15 | { 16 | protected override void BuildModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .HasAnnotation("ProductVersion", "2.0.0-rtm-26452") 21 | .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); 22 | 23 | modelBuilder.Entity("Northwind.Domain.Categories.Category", b => 24 | { 25 | b.Property("Id") 26 | .ValueGeneratedOnAdd(); 27 | 28 | b.Property("Created"); 29 | 30 | b.Property("Description"); 31 | 32 | b.Property("Modified"); 33 | 34 | b.Property("Name"); 35 | 36 | b.HasKey("Id"); 37 | 38 | b.ToTable("Categories"); 39 | }); 40 | 41 | modelBuilder.Entity("Northwind.Domain.Customers.Customer", b => 42 | { 43 | b.Property("Id") 44 | .ValueGeneratedOnAdd(); 45 | 46 | b.Property("City"); 47 | 48 | b.Property("Contact"); 49 | 50 | b.Property("ContactEMail"); 51 | 52 | b.Property("Country"); 53 | 54 | b.Property("Created"); 55 | 56 | b.Property("CustomerId"); 57 | 58 | b.Property("Modified"); 59 | 60 | b.Property("Title"); 61 | 62 | b.HasKey("Id"); 63 | 64 | b.ToTable("Customers"); 65 | }); 66 | 67 | modelBuilder.Entity("Northwind.Domain.Employees.Employee", b => 68 | { 69 | b.Property("Id") 70 | .ValueGeneratedOnAdd(); 71 | 72 | b.Property("BirthDate"); 73 | 74 | b.Property("City"); 75 | 76 | b.Property("Country"); 77 | 78 | b.Property("Created"); 79 | 80 | b.Property("EMail"); 81 | 82 | b.Property("FirstName"); 83 | 84 | b.Property("HireDate"); 85 | 86 | b.Property("LastName"); 87 | 88 | b.Property("ManagerId"); 89 | 90 | b.Property("Modified"); 91 | 92 | b.HasKey("Id"); 93 | 94 | b.ToTable("Employees"); 95 | }); 96 | 97 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 98 | { 99 | b.Property("Id") 100 | .ValueGeneratedOnAdd(); 101 | 102 | b.Property("Created"); 103 | 104 | b.Property("Discount"); 105 | 106 | b.Property("Modified"); 107 | 108 | b.Property("OrderId"); 109 | 110 | b.Property("Price"); 111 | 112 | b.Property("ProductId"); 113 | 114 | b.Property("Quantity"); 115 | 116 | b.HasKey("Id"); 117 | 118 | b.HasIndex("OrderId"); 119 | 120 | b.HasIndex("ProductId"); 121 | 122 | b.ToTable("OrderDetails"); 123 | }); 124 | 125 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 126 | { 127 | b.Property("Id") 128 | .ValueGeneratedOnAdd(); 129 | 130 | b.Property("Created"); 131 | 132 | b.Property("CustomerId"); 133 | 134 | b.Property("EmployeeId"); 135 | 136 | b.Property("IsUrgent"); 137 | 138 | b.Property("LastShipDate"); 139 | 140 | b.Property("Modified"); 141 | 142 | b.HasKey("Id"); 143 | 144 | b.HasIndex("CustomerId"); 145 | 146 | b.HasIndex("EmployeeId"); 147 | 148 | b.ToTable("Orders"); 149 | }); 150 | 151 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 152 | { 153 | b.Property("Id") 154 | .ValueGeneratedOnAdd(); 155 | 156 | b.Property("CategoryId"); 157 | 158 | b.Property("Created"); 159 | 160 | b.Property("Modified"); 161 | 162 | b.Property("Name"); 163 | 164 | b.Property("SupplierId"); 165 | 166 | b.Property("UnitPrice"); 167 | 168 | b.Property("UnitsInStock"); 169 | 170 | b.HasKey("Id"); 171 | 172 | b.HasIndex("CategoryId"); 173 | 174 | b.HasIndex("SupplierId"); 175 | 176 | b.ToTable("Products"); 177 | }); 178 | 179 | modelBuilder.Entity("Northwind.Domain.Suppliers.Supplier", b => 180 | { 181 | b.Property("Id") 182 | .ValueGeneratedOnAdd(); 183 | 184 | b.Property("City"); 185 | 186 | b.Property("CompanyName"); 187 | 188 | b.Property("Country"); 189 | 190 | b.Property("Created"); 191 | 192 | b.Property("Email"); 193 | 194 | b.Property("Fax"); 195 | 196 | b.Property("Manager"); 197 | 198 | b.Property("Modified"); 199 | 200 | b.Property("Phone"); 201 | 202 | b.HasKey("Id"); 203 | 204 | b.ToTable("Suppliers"); 205 | }); 206 | 207 | modelBuilder.Entity("Northwind.Domain.OrderDetails.OrderDetail", b => 208 | { 209 | b.HasOne("Northwind.Domain.Orders.Order") 210 | .WithMany() 211 | .HasForeignKey("OrderId") 212 | .OnDelete(DeleteBehavior.Cascade); 213 | 214 | b.HasOne("Northwind.Domain.Products.Product") 215 | .WithMany() 216 | .HasForeignKey("ProductId") 217 | .OnDelete(DeleteBehavior.Cascade); 218 | }); 219 | 220 | modelBuilder.Entity("Northwind.Domain.Orders.Order", b => 221 | { 222 | b.HasOne("Northwind.Domain.Customers.Customer") 223 | .WithMany("Orders") 224 | .HasForeignKey("CustomerId"); 225 | 226 | b.HasOne("Northwind.Domain.Employees.Employee") 227 | .WithMany() 228 | .HasForeignKey("EmployeeId") 229 | .OnDelete(DeleteBehavior.Cascade); 230 | }); 231 | 232 | modelBuilder.Entity("Northwind.Domain.Products.Product", b => 233 | { 234 | b.HasOne("Northwind.Domain.Categories.Category") 235 | .WithMany("Products") 236 | .HasForeignKey("CategoryId") 237 | .OnDelete(DeleteBehavior.Cascade); 238 | 239 | b.HasOne("Northwind.Domain.Suppliers.Supplier") 240 | .WithMany("Products") 241 | .HasForeignKey("SupplierId") 242 | .OnDelete(DeleteBehavior.Cascade); 243 | }); 244 | #pragma warning restore 612, 618 245 | } 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Northwind.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore\2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/OrderDetails/OrderDetailDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Application.OrderDetails 6 | { 7 | public class OrderDetailDto 8 | { 9 | public long Id { get; set; } 10 | public long OrderId { get; set; } 11 | public long ProductId { get; set; } 12 | public decimal Price { get; set; } 13 | public double Quantity { get; set; } 14 | public double Discount { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/OrderDetails/OrderDetailService.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Services; 2 | using Northwind.Domain.OrderDetails; 3 | using Northwind.Framework.Domain; 4 | using Northwind.Framework.Helpers; 5 | 6 | namespace Northwind.Application.OrderDetails 7 | { 8 | public class OrderDetailService : IDomainService 9 | { 10 | private readonly IOrderDetailRepository _repo; 11 | private readonly IUnitOfWork _unitOfWork; 12 | 13 | public OrderDetailService(IOrderDetailRepository repo, IUnitOfWork unitOfWork) 14 | { 15 | _repo = repo; 16 | _unitOfWork = unitOfWork; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Orders/OrderDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Application.Orders 6 | { 7 | public class OrderDto 8 | { 9 | public long Id { get; set; } 10 | public string CustomerId { get; set; } 11 | public bool IsUrgent { get; set; } 12 | public DateTime? LastShipDate { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Orders/OrderService.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Orders; 2 | using Northwind.Framework.Domain; 3 | using Northwind.Framework.Helpers; 4 | 5 | namespace Northwind.Application.Orders 6 | { 7 | public class OrderService : IDomainService 8 | { 9 | private readonly IOrderRepository _repo; 10 | private readonly IUnitOfWork _unitOfWork; 11 | 12 | public OrderService(IOrderRepository repo, IUnitOfWork unitOfWork) 13 | { 14 | _repo = repo; 15 | _unitOfWork = unitOfWork; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Products/ProductDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Application.Products 6 | { 7 | public class ProductDto 8 | { 9 | public long Id { get; set; } 10 | public string ProductName { get; set; } 11 | public decimal Price { get; set; } 12 | public double UnitsInStock { get; set; } 13 | public int CategoryId { get; set; } 14 | public int SupplierId { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Products/ProductManager.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Products; 2 | using Northwind.Framework.Helpers; 3 | using Northwind.Framework.Domain; 4 | using Northwind.Domain.Categories; 5 | using System.Collections.Generic; 6 | using Northwind.Framework; 7 | using System.Linq; 8 | using Northwind.Application.Mappers; 9 | 10 | namespace Northwind.Application.Products 11 | { 12 | public class ProductManager : IDomainService 13 | { 14 | private readonly IProductRepository _repo; 15 | private readonly IUnitOfWork _unitOfWork; 16 | 17 | public ProductManager(IProductRepository repo, IUnitOfWork unitOfWork) 18 | { 19 | _repo = repo; 20 | _unitOfWork = unitOfWork; 21 | } 22 | 23 | public IEnumerable GetProductsByCategory(Category category) 24 | { 25 | TypeCheck.IsNull(category); 26 | TypeCheck.IsUsableAsId(category.Id); 27 | var filter = new ProductByCategoryFilter(category.Id); 28 | return _repo.Find(filter).Select(i => i.ToDto()); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Products/ProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Products; 2 | using System.Collections.Generic; 3 | using Microsoft.EntityFrameworkCore; 4 | using Northwind.Framework.Helpers; 5 | using System.Linq; 6 | using Northwind.Framework.Domain.Exceptions; 7 | 8 | namespace Northwind.Application.Products 9 | { 10 | internal class ProductRepository : IProductRepository 11 | { 12 | private readonly IUnitOfWork _unitOfwork; 13 | public ProductRepository(IUnitOfWork unitOfwork) 14 | { 15 | _unitOfwork = unitOfwork; 16 | } 17 | public DbSet Repository => _unitOfwork.GetDbSet(); 18 | 19 | public IEnumerable Find(IFilter filter) 20 | { 21 | var items = Repository.Where(filter.FilterExpression).ToList(); 22 | return items; 23 | } 24 | 25 | public Product FindById(long id) 26 | { 27 | var product = Repository.FirstOrDefault(i => i.Id == id); 28 | if (product == null) 29 | { 30 | throw new NotFoundByIdException(); 31 | } 32 | return product; 33 | } 34 | 35 | public Product FindSingle(IFilter spec) 36 | { 37 | return Repository.Where(spec.FilterExpression).SingleOrDefault(); 38 | } 39 | 40 | public void Remove(Product entity) 41 | { 42 | Repository.Remove(entity); 43 | } 44 | 45 | public void Save(Product entity) 46 | { 47 | Repository.Add(entity); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Suppliers/SupplierDto.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Application.Suppliers 6 | { 7 | public class SupplierDto 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Application/Suppliers/SupplierService.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Suppliers; 2 | using Northwind.Framework.Helpers; 3 | using Northwind.Framework.Domain; 4 | 5 | namespace Northwind.Application.Suppliers 6 | { 7 | public class SupplierService : IDomainService 8 | { 9 | private readonly ISupplierRepository _repo; 10 | private readonly IUnitOfWork _unitOfWork; 11 | 12 | public SupplierService(ISupplierRepository repo, IUnitOfWork unitOfWork) 13 | { 14 | _repo = repo; 15 | _unitOfWork = unitOfWork; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DDD.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27004.2006 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Northwind.Web", "Northwind.Web\Northwind.Web.csproj", "{2E802609-7A27-49BE-AA46-E75FF4DBEB72}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Layers", "Layers", "{8658ABC7-37AD-481D-9F9A-9AB00CC43CF0}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Northwind.Domain", "Northwind.Domain\Northwind.Domain.csproj", "{69D7FDD9-5E31-4C84-A8E9-07C3730481E9}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Northwind.Application", "Northwind.Application\Northwind.Application.csproj", "{72F4C448-5C0F-4872-8DD7-1B26D981B68D}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Northwind.Framework", "Northwind.Framework\Northwind.Framework.csproj", "{D2A1711A-CFC2-4673-9578-7B18BF9818A8}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{64E8A160-5F97-473E-A904-925AF000E0CC}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Northwind.UnitTests", "Northwind.UnitTests\Northwind.UnitTests.csproj", "{F9CE71A1-F352-4103-A28F-CEBF8CD37D5A}" 19 | EndProject 20 | Project("{00D1A9C2-B5F0-4AF3-8072-F6C62B433612}") = "Northwind.DataBase", "Northwind.DataBase\Northwind.DataBase.sqlproj", "{FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}" 21 | EndProject 22 | Global 23 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 24 | Debug|Any CPU = Debug|Any CPU 25 | Release|Any CPU = Release|Any CPU 26 | EndGlobalSection 27 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 28 | {2E802609-7A27-49BE-AA46-E75FF4DBEB72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {2E802609-7A27-49BE-AA46-E75FF4DBEB72}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {2E802609-7A27-49BE-AA46-E75FF4DBEB72}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {2E802609-7A27-49BE-AA46-E75FF4DBEB72}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {69D7FDD9-5E31-4C84-A8E9-07C3730481E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {69D7FDD9-5E31-4C84-A8E9-07C3730481E9}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {69D7FDD9-5E31-4C84-A8E9-07C3730481E9}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {69D7FDD9-5E31-4C84-A8E9-07C3730481E9}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {72F4C448-5C0F-4872-8DD7-1B26D981B68D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {72F4C448-5C0F-4872-8DD7-1B26D981B68D}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {72F4C448-5C0F-4872-8DD7-1B26D981B68D}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {72F4C448-5C0F-4872-8DD7-1B26D981B68D}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {D2A1711A-CFC2-4673-9578-7B18BF9818A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {D2A1711A-CFC2-4673-9578-7B18BF9818A8}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {D2A1711A-CFC2-4673-9578-7B18BF9818A8}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {D2A1711A-CFC2-4673-9578-7B18BF9818A8}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {F9CE71A1-F352-4103-A28F-CEBF8CD37D5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {F9CE71A1-F352-4103-A28F-CEBF8CD37D5A}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {F9CE71A1-F352-4103-A28F-CEBF8CD37D5A}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {F9CE71A1-F352-4103-A28F-CEBF8CD37D5A}.Release|Any CPU.Build.0 = Release|Any CPU 48 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Debug|Any CPU.Deploy.0 = Debug|Any CPU 51 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Release|Any CPU.ActiveCfg = Release|Any CPU 52 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Release|Any CPU.Build.0 = Release|Any CPU 53 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93}.Release|Any CPU.Deploy.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(NestedProjects) = preSolution 59 | {69D7FDD9-5E31-4C84-A8E9-07C3730481E9} = {8658ABC7-37AD-481D-9F9A-9AB00CC43CF0} 60 | {72F4C448-5C0F-4872-8DD7-1B26D981B68D} = {8658ABC7-37AD-481D-9F9A-9AB00CC43CF0} 61 | {D2A1711A-CFC2-4673-9578-7B18BF9818A8} = {8658ABC7-37AD-481D-9F9A-9AB00CC43CF0} 62 | {F9CE71A1-F352-4103-A28F-CEBF8CD37D5A} = {64E8A160-5F97-473E-A904-925AF000E0CC} 63 | {FD6DD120-F5D6-4214-BCF6-D03AC2A11A93} = {64E8A160-5F97-473E-A904-925AF000E0CC} 64 | EndGlobalSection 65 | GlobalSection(ExtensibilityGlobals) = postSolution 66 | SolutionGuid = {AF711025-3661-47E7-9718-738A80AFDB9E} 67 | EndGlobalSection 68 | EndGlobal 69 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DataBase/Data/Categories.sql: -------------------------------------------------------------------------------- 1 | USE [NorthwindDomainDriven] 2 | GO 3 | /****** Object: Table [dbo].[Categories] Script Date: 11/22/2017 1:24:27 PM ******/ 4 | DROP TABLE IF EXISTS [dbo].[Categories] 5 | GO 6 | /****** Object: Table [dbo].[Categories] Script Date: 11/22/2017 1:24:27 PM ******/ 7 | SET ANSI_NULLS ON 8 | GO 9 | SET QUOTED_IDENTIFIER ON 10 | GO 11 | IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Categories]') AND type in (N'U')) 12 | BEGIN 13 | CREATE TABLE [dbo].[Categories]( 14 | [Id] [int] IDENTITY(1,1) NOT NULL, 15 | [Created] [datetime2](7) NOT NULL, 16 | [Description] [nvarchar](max) NULL, 17 | [Modified] [datetime2](7) NOT NULL, 18 | [Name] [nvarchar](max) NULL, 19 | CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED 20 | ( 21 | [Id] ASC 22 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 23 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 24 | END 25 | GO 26 | SET IDENTITY_INSERT [dbo].[Categories] ON 27 | GO 28 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (1, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Soft drinks, coffees, teas, beers, and ales', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Beverages') 29 | GO 30 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (2, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Sweet and savory sauces, relishes, spreads, and seasonings', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Condiments') 31 | GO 32 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (3, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Desserts, candies, and sweet breads', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Confections') 33 | GO 34 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (4, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Cheeses', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Dairy Products') 35 | GO 36 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (5, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Breads, crackers, pasta, and cereal', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Grains/Cereals') 37 | GO 38 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (6, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Prepared meats', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Meat/Poultry') 39 | GO 40 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (7, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Dried fruit and bean curd', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Produce') 41 | GO 42 | INSERT [dbo].[Categories] ([Id], [Created], [Description], [Modified], [Name]) VALUES (8, CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Seaweed and fish', CAST(N'2017-11-22T13:23:20.5900000' AS DateTime2), N'Seafood') 43 | GO 44 | SET IDENTITY_INSERT [dbo].[Categories] OFF 45 | GO 46 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DataBase/Data/Employees.sql: -------------------------------------------------------------------------------- 1 | USE [NorthwindDomainDriven] 2 | GO 3 | /****** Object: Table [dbo].[Employees] Script Date: 11/8/2017 4:15:24 PM ******/ 4 | DROP TABLE IF EXISTS [dbo].[Employees] 5 | GO 6 | /****** Object: Table [dbo].[Employees] Script Date: 11/8/2017 4:15:24 PM ******/ 7 | SET ANSI_NULLS ON 8 | GO 9 | SET QUOTED_IDENTIFIER ON 10 | GO 11 | CREATE TABLE [dbo].[Employees]( 12 | [Id] [int] IDENTITY(1,1) NOT NULL, 13 | [FirstName] [nvarchar](max) NULL, 14 | [LastName] [nvarchar](max) NULL, 15 | [HireDate] [datetime2](7) NULL, 16 | [BirthDate] [datetime2](7) NULL, 17 | [City] [nvarchar](max) NULL, 18 | [Country] [nvarchar](max) NULL, 19 | [Created] [datetime2](7) NOT NULL, 20 | [EMail] [nvarchar](max) NULL, 21 | [ManagerId] [bigint] NULL, 22 | [Modified] [datetime2](7) NOT NULL, 23 | CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED 24 | ( 25 | [Id] ASC 26 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 27 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 28 | GO 29 | SET IDENTITY_INSERT [dbo].[Employees] ON 30 | GO 31 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (1, N'Nancy', N'Davolio', CAST(N'2015-05-01T00:00:00.0000000' AS DateTime2), CAST(N'1982-12-08T00:00:00.0000000' AS DateTime2), N'Seattle', N'USA', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'nancy@mail.com', 2, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 32 | GO 33 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (2, N'Andrew', N'Fuller', CAST(N'2016-08-14T00:00:00.0000000' AS DateTime2), CAST(N'1982-02-19T00:00:00.0000000' AS DateTime2), N'Tacoma', N'USA', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'andrew@mail.com', NULL, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 34 | GO 35 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (3, N'Janet', N'Leverling', CAST(N'2014-04-01T00:00:00.0000000' AS DateTime2), CAST(N'1983-08-30T00:00:00.0000000' AS DateTime2), N'Kirkland', N'USA', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'janet@mail.com', 2, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 36 | GO 37 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (4, N'Margaret', N'Peacock', CAST(N'2016-05-03T00:00:00.0000000' AS DateTime2), CAST(N'1987-09-19T00:00:00.0000000' AS DateTime2), N'Redmond', N'USA', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'margaret@mail.com', 2, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 38 | GO 39 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (5, N'Steven', N'Buchanan', CAST(N'2015-10-17T00:00:00.0000000' AS DateTime2), CAST(N'1985-03-04T00:00:00.0000000' AS DateTime2), N'London', N'UK', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'steven@mail.com', 2, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 40 | GO 41 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (6, N'Michael', N'Suyama', CAST(N'2014-10-17T00:00:00.0000000' AS DateTime2), CAST(N'1983-07-02T00:00:00.0000000' AS DateTime2), N'London', N'UK', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'michael@mail.com', 5, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 42 | GO 43 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (7, N'Robert', N'King', CAST(N'2013-01-02T00:00:00.0000000' AS DateTime2), CAST(N'1980-05-29T00:00:00.0000000' AS DateTime2), N'London', N'UK', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'robert@mail.com', 5, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 44 | GO 45 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (8, N'Laura', N'Callahan', CAST(N'1994-03-05T00:00:00.0000000' AS DateTime2), CAST(N'1988-01-09T00:00:00.0000000' AS DateTime2), N'Seattle', N'USA', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'laura@mail.com', 2, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 46 | GO 47 | INSERT [dbo].[Employees] ([Id], [FirstName], [LastName], [HireDate], [BirthDate], [City], [Country], [Created], [EMail], [ManagerId], [Modified]) VALUES (9, N'Anne', N'Dodsworth', CAST(N'2016-11-15T00:00:00.0000000' AS DateTime2), CAST(N'1986-01-27T00:00:00.0000000' AS DateTime2), N'London', N'UK', CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2), N'anne@mail.com', 5, CAST(N'2017-11-08T16:10:19.2266667' AS DateTime2)) 48 | GO 49 | SET IDENTITY_INSERT [dbo].[Employees] OFF 50 | GO 51 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DataBase/Data/Products.sql: -------------------------------------------------------------------------------- 1 | USE [NorthwindDomainDriven] 2 | GO 3 | IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products]') AND type in (N'U')) 4 | ALTER TABLE [dbo].[Products] DROP CONSTRAINT IF EXISTS [FK_Products_Suppliers_SupplierId] 5 | GO 6 | IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products]') AND type in (N'U')) 7 | ALTER TABLE [dbo].[Products] DROP CONSTRAINT IF EXISTS [FK_Products_Categories_CategoryId] 8 | GO 9 | /****** Object: Table [dbo].[Products] Script Date: 11/22/2017 2:03:25 PM ******/ 10 | DROP TABLE IF EXISTS [dbo].[Products] 11 | GO 12 | /****** Object: Table [dbo].[Products] Script Date: 11/22/2017 2:03:25 PM ******/ 13 | SET ANSI_NULLS ON 14 | GO 15 | SET QUOTED_IDENTIFIER ON 16 | GO 17 | IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Products]') AND type in (N'U')) 18 | BEGIN 19 | CREATE TABLE [dbo].[Products]( 20 | [Id] [bigint] IDENTITY(1,1) NOT NULL, 21 | [CategoryId] [int] NOT NULL, 22 | [Created] [datetime2](7) NOT NULL, 23 | [Modified] [datetime2](7) NOT NULL, 24 | [Name] [nvarchar](max) NULL, 25 | [SupplierId] [int] NOT NULL, 26 | [UnitPrice] [decimal](18, 2) NOT NULL, 27 | [UnitsInStock] [float] NOT NULL, 28 | CONSTRAINT [PK_Products] PRIMARY KEY CLUSTERED 29 | ( 30 | [Id] ASC 31 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 32 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 33 | END 34 | GO 35 | SET IDENTITY_INSERT [dbo].[Products] ON 36 | GO 37 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (1, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chai', 1, CAST(18.00 AS Decimal(18, 2)), 39) 38 | GO 39 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (2, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chang', 1, CAST(19.00 AS Decimal(18, 2)), 17) 40 | GO 41 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (3, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Aniseed Syrup', 1, CAST(10.00 AS Decimal(18, 2)), 13) 42 | GO 43 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (4, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chef Anton''s Cajun Seasoning', 2, CAST(22.00 AS Decimal(18, 2)), 53) 44 | GO 45 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (5, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chef Anton''s Gumbo Mix', 2, CAST(21.35 AS Decimal(18, 2)), 0) 46 | GO 47 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (6, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Grandma''s Boysenberry Spread', 3, CAST(25.00 AS Decimal(18, 2)), 120) 48 | GO 49 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (7, 7, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Uncle Bob''s Organic Dried Pears', 3, CAST(30.00 AS Decimal(18, 2)), 15) 50 | GO 51 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (8, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Northwoods Cranberry Sauce', 3, CAST(40.00 AS Decimal(18, 2)), 6) 52 | GO 53 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (9, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Mishi Kobe Niku', 4, CAST(97.00 AS Decimal(18, 2)), 29) 54 | GO 55 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (10, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Ikura', 4, CAST(31.00 AS Decimal(18, 2)), 31) 56 | GO 57 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (11, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Queso Cabrales', 5, CAST(21.00 AS Decimal(18, 2)), 22) 58 | GO 59 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (12, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Queso Manchego La Pastora', 5, CAST(38.00 AS Decimal(18, 2)), 86) 60 | GO 61 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (13, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Konbu', 6, CAST(6.00 AS Decimal(18, 2)), 24) 62 | GO 63 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (14, 7, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Tofu', 6, CAST(23.25 AS Decimal(18, 2)), 35) 64 | GO 65 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (15, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Genen Shouyu', 6, CAST(15.50 AS Decimal(18, 2)), 39) 66 | GO 67 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (16, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Pavlova', 7, CAST(17.45 AS Decimal(18, 2)), 29) 68 | GO 69 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (17, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Alice Mutton', 7, CAST(39.00 AS Decimal(18, 2)), 0) 70 | GO 71 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (18, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Carnarvon Tigers', 7, CAST(62.50 AS Decimal(18, 2)), 42) 72 | GO 73 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (19, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Teatime Chocolate Biscuits', 8, CAST(9.20 AS Decimal(18, 2)), 25) 74 | GO 75 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (20, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Sir Rodney''s Marmalade', 8, CAST(81.00 AS Decimal(18, 2)), 40) 76 | GO 77 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (21, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Sir Rodney''s Scones', 8, CAST(10.00 AS Decimal(18, 2)), 3) 78 | GO 79 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (22, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gustaf''s Knäckebröd', 9, CAST(21.00 AS Decimal(18, 2)), 104) 80 | GO 81 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (23, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Tunnbröd', 9, CAST(9.00 AS Decimal(18, 2)), 61) 82 | GO 83 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (24, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Guaraná Fantástica', 10, CAST(4.50 AS Decimal(18, 2)), 20) 84 | GO 85 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (25, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'NuNuCa Nuß-Nougat-Creme', 11, CAST(14.00 AS Decimal(18, 2)), 76) 86 | GO 87 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (26, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gumbär Gummibärchen', 11, CAST(31.23 AS Decimal(18, 2)), 15) 88 | GO 89 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (27, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Schoggi Schokolade', 11, CAST(43.90 AS Decimal(18, 2)), 49) 90 | GO 91 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (28, 7, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Rössle Sauerkraut', 12, CAST(45.60 AS Decimal(18, 2)), 26) 92 | GO 93 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (29, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Thüringer Rostbratwurst', 12, CAST(123.79 AS Decimal(18, 2)), 0) 94 | GO 95 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (30, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Nord-Ost Matjeshering', 13, CAST(25.89 AS Decimal(18, 2)), 10) 96 | GO 97 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (31, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gorgonzola Telino', 14, CAST(12.50 AS Decimal(18, 2)), 0) 98 | GO 99 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (32, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Mascarpone Fabioli', 14, CAST(32.00 AS Decimal(18, 2)), 9) 100 | GO 101 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (33, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Geitost', 15, CAST(2.50 AS Decimal(18, 2)), 112) 102 | GO 103 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (34, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Sasquatch Ale', 16, CAST(14.00 AS Decimal(18, 2)), 111) 104 | GO 105 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (35, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Steeleye Stout', 16, CAST(18.00 AS Decimal(18, 2)), 20) 106 | GO 107 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (36, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Inlagd Sill', 17, CAST(19.00 AS Decimal(18, 2)), 112) 108 | GO 109 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (37, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gravad lax', 17, CAST(26.00 AS Decimal(18, 2)), 11) 110 | GO 111 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (38, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Côte de Blaye', 18, CAST(263.50 AS Decimal(18, 2)), 17) 112 | GO 113 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (39, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chartreuse verte', 18, CAST(18.00 AS Decimal(18, 2)), 69) 114 | GO 115 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (40, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Boston Crab Meat', 19, CAST(18.40 AS Decimal(18, 2)), 123) 116 | GO 117 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (41, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Jack''s New England Clam Chowder', 19, CAST(9.65 AS Decimal(18, 2)), 85) 118 | GO 119 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (42, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Singaporean Hokkien Fried Mee', 20, CAST(14.00 AS Decimal(18, 2)), 26) 120 | GO 121 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (43, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Ipoh Coffee', 20, CAST(46.00 AS Decimal(18, 2)), 17) 122 | GO 123 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (44, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gula Malacca', 20, CAST(19.45 AS Decimal(18, 2)), 27) 124 | GO 125 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (45, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Rogede sild', 21, CAST(9.50 AS Decimal(18, 2)), 5) 126 | GO 127 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (46, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Spegesild', 21, CAST(12.00 AS Decimal(18, 2)), 95) 128 | GO 129 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (47, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Zaanse koeken', 22, CAST(9.50 AS Decimal(18, 2)), 36) 130 | GO 131 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (48, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Chocolade', 22, CAST(12.75 AS Decimal(18, 2)), 15) 132 | GO 133 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (49, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Maxilaku', 23, CAST(20.00 AS Decimal(18, 2)), 10) 134 | GO 135 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (50, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Valkoinen suklaa', 23, CAST(16.25 AS Decimal(18, 2)), 65) 136 | GO 137 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (51, 7, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Manjimup Dried Apples', 24, CAST(53.00 AS Decimal(18, 2)), 20) 138 | GO 139 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (52, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Filo Mix', 24, CAST(7.00 AS Decimal(18, 2)), 38) 140 | GO 141 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (53, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Perth Pasties', 24, CAST(32.80 AS Decimal(18, 2)), 0) 142 | GO 143 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (54, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Tourtière', 25, CAST(7.45 AS Decimal(18, 2)), 21) 144 | GO 145 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (55, 6, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Pâté chinois', 25, CAST(24.00 AS Decimal(18, 2)), 115) 146 | GO 147 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (56, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gnocchi di nonna Alice', 26, CAST(38.00 AS Decimal(18, 2)), 21) 148 | GO 149 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (57, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Ravioli Angelo', 26, CAST(19.50 AS Decimal(18, 2)), 36) 150 | GO 151 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (58, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Escargots de Bourgogne', 27, CAST(13.25 AS Decimal(18, 2)), 62) 152 | GO 153 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (59, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Raclette Courdavault', 28, CAST(55.00 AS Decimal(18, 2)), 79) 154 | GO 155 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (60, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Camembert Pierrot', 28, CAST(34.00 AS Decimal(18, 2)), 19) 156 | GO 157 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (61, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Sirop d''érable', 29, CAST(28.50 AS Decimal(18, 2)), 113) 158 | GO 159 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (62, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Tarte au sucre', 29, CAST(49.30 AS Decimal(18, 2)), 17) 160 | GO 161 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (63, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Vegie-spread', 7, CAST(43.90 AS Decimal(18, 2)), 24) 162 | GO 163 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (64, 5, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Wimmers gute Semmelknödel', 12, CAST(33.25 AS Decimal(18, 2)), 22) 164 | GO 165 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (65, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Louisiana Fiery Hot Pepper Sauce', 2, CAST(21.05 AS Decimal(18, 2)), 76) 166 | GO 167 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (66, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Louisiana Hot Spiced Okra', 2, CAST(17.00 AS Decimal(18, 2)), 4) 168 | GO 169 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (67, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Laughing Lumberjack Lager', 16, CAST(14.00 AS Decimal(18, 2)), 52) 170 | GO 171 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (68, 3, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Scottish Longbreads', 8, CAST(12.50 AS Decimal(18, 2)), 6) 172 | GO 173 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (69, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Gudbrandsdalsost', 15, CAST(36.00 AS Decimal(18, 2)), 26) 174 | GO 175 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (70, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Outback Lager', 7, CAST(15.00 AS Decimal(18, 2)), 15) 176 | GO 177 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (71, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Flotemysost', 15, CAST(21.50 AS Decimal(18, 2)), 26) 178 | GO 179 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (72, 4, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Mozzarella di Giovanni', 14, CAST(34.80 AS Decimal(18, 2)), 14) 180 | GO 181 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (73, 8, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Röd Kaviar', 17, CAST(15.00 AS Decimal(18, 2)), 101) 182 | GO 183 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (74, 7, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Longlife Tofu', 4, CAST(10.00 AS Decimal(18, 2)), 4) 184 | GO 185 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (75, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Rhönbräu Klosterbier', 12, CAST(7.75 AS Decimal(18, 2)), 125) 186 | GO 187 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (76, 1, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Lakkalikööri', 23, CAST(18.00 AS Decimal(18, 2)), 57) 188 | GO 189 | INSERT [dbo].[Products] ([Id], [CategoryId], [Created], [Modified], [Name], [SupplierId], [UnitPrice], [UnitsInStock]) VALUES (77, 2, CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), CAST(N'2017-11-22T14:01:16.1133333' AS DateTime2), N'Original Frankfurter grüne Soße', 12, CAST(13.00 AS Decimal(18, 2)), 32) 190 | GO 191 | SET IDENTITY_INSERT [dbo].[Products] OFF 192 | GO 193 | IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Products_Categories_CategoryId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Products]')) 194 | ALTER TABLE [dbo].[Products] WITH CHECK ADD CONSTRAINT [FK_Products_Categories_CategoryId] FOREIGN KEY([CategoryId]) 195 | REFERENCES [dbo].[Categories] ([Id]) 196 | ON DELETE CASCADE 197 | GO 198 | IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Products_Categories_CategoryId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Products]')) 199 | ALTER TABLE [dbo].[Products] CHECK CONSTRAINT [FK_Products_Categories_CategoryId] 200 | GO 201 | IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Products_Suppliers_SupplierId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Products]')) 202 | ALTER TABLE [dbo].[Products] WITH CHECK ADD CONSTRAINT [FK_Products_Suppliers_SupplierId] FOREIGN KEY([SupplierId]) 203 | REFERENCES [dbo].[Suppliers] ([Id]) 204 | ON DELETE CASCADE 205 | GO 206 | IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Products_Suppliers_SupplierId]') AND parent_object_id = OBJECT_ID(N'[dbo].[Products]')) 207 | ALTER TABLE [dbo].[Products] CHECK CONSTRAINT [FK_Products_Suppliers_SupplierId] 208 | GO 209 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DataBase/Data/Suppliers.sql: -------------------------------------------------------------------------------- 1 | USE [NorthwindDomainDriven] 2 | GO 3 | /****** Object: Table [dbo].[Suppliers] Script Date: 11/22/2017 2:04:14 PM ******/ 4 | DROP TABLE IF EXISTS [dbo].[Suppliers] 5 | GO 6 | /****** Object: Table [dbo].[Suppliers] Script Date: 11/22/2017 2:04:14 PM ******/ 7 | SET ANSI_NULLS ON 8 | GO 9 | SET QUOTED_IDENTIFIER ON 10 | GO 11 | IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Suppliers]') AND type in (N'U')) 12 | BEGIN 13 | CREATE TABLE [dbo].[Suppliers]( 14 | [Id] [int] IDENTITY(1,1) NOT NULL, 15 | [City] [nvarchar](max) NULL, 16 | [CompanyName] [nvarchar](max) NULL, 17 | [Country] [nvarchar](max) NULL, 18 | [Created] [datetime2](7) NOT NULL, 19 | [Email] [nvarchar](max) NULL, 20 | [Fax] [nvarchar](max) NULL, 21 | [Manager] [nvarchar](max) NULL, 22 | [Modified] [datetime2](7) NOT NULL, 23 | [Phone] [nvarchar](max) NULL, 24 | CONSTRAINT [PK_Suppliers] PRIMARY KEY CLUSTERED 25 | ( 26 | [Id] ASC 27 | )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 28 | ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 29 | END 30 | GO 31 | SET IDENTITY_INSERT [dbo].[Suppliers] ON 32 | GO 33 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (1, N'London', N'Exotic Liquids', N'UK', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Charlotte Cooper', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(171) 555-2222') 34 | GO 35 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (2, N'New Orleans', N'New Orleans Cajun Delights', N'USA', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Shelley Burke', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(100) 555-4822') 36 | GO 37 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (3, N'Ann Arbor', N'Grandma Kelly''s Homestead', N'USA', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(313) 555-3349', N'Regina Murphy', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(313) 555-5735') 38 | GO 39 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (4, N'Tokyo', N'Tokyo Traders', N'Japan', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Yoshi Nagase', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(03) 3555-5011') 40 | GO 41 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (5, N'Oviedo', N'Cooperativa de Quesos ''Las Cabras''', N'Spain', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Antonio del Valle Saavedra', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(98) 598 76 54') 42 | GO 43 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (6, N'Osaka', N'Mayumi''s', N'Japan', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Mayumi Ohno', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(06) 431-7877') 44 | GO 45 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (7, N'Melbourne', N'Pavlova, Ltd.', N'Australia', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(03) 444-6588', N'Ian Devling', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(03) 444-2343') 46 | GO 47 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (8, N'Manchester', N'Specialty Biscuits, Ltd.', N'UK', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Peter Wilson', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(161) 555-4448') 48 | GO 49 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (9, N'Göteborg', N'PB Knäckebröd AB', N'Sweden', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'031-987 65 91', N'Lars Peterson', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'031-987 65 43') 50 | GO 51 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (10, N'Sao Paulo', N'Refrescos Americanas LTDA', N'Brazil', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Carlos Diaz', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(11) 555 4640') 52 | GO 53 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (11, N'Berlin', N'Heli Süßwaren GmbH & Co. KG', N'Germany', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Petra Winkler', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(010) 9984510') 54 | GO 55 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (12, N'Frankfurt', N'Plutzer Lebensmittelgroßmärkte AG', N'Germany', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Martin Bein', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(069) 992755') 56 | GO 57 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (13, N'Cuxhaven', N'Nord-Ost-Fisch Handelsgesellschaft mbH', N'Germany', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(04721) 8714', N'Sven Petersen', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(04721) 8713') 58 | GO 59 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (14, N'Ravenna', N'Formaggi Fortini s.r.l.', N'Italy', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(0544) 60603', N'Elio Rossi', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(0544) 60323') 60 | GO 61 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (15, N'Sandvika', N'Norske Meierier', N'Norway', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Beate Vileid', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(0)2-953010') 62 | GO 63 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (16, N'Bend', N'Bigfoot Breweries', N'USA', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Cheryl Saylor', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(503) 555-9931') 64 | GO 65 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (17, N'Stockholm', N'Svensk Sjöföda AB', N'Sweden', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Michael Björn', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'08-123 45 67') 66 | GO 67 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (18, N'Paris', N'Aux joyeux ecclésiastiques', N'France', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(1) 03.83.00.62', N'Guylène Nodier', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(1) 03.83.00.68') 68 | GO 69 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (19, N'Boston', N'New England Seafood Cannery', N'USA', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(617) 555-3389', N'Robb Merchant', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(617) 555-3267') 70 | GO 71 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (20, N'Singapore', N'Leka Trading', N'Singapore', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Chandra Leka', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'555-8787') 72 | GO 73 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (21, N'Lyngby', N'Lyngbysild', N'Denmark', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'43844115', N'Niels Petersen', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'43844108') 74 | GO 75 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (22, N'Zaandam', N'Zaanse Snoepfabriek', N'Netherlands', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(12345) 1210', N'Dirk Luchte', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(12345) 1212') 76 | GO 77 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (23, N'Lappeenranta', N'Karkki Oy', N'Finland', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Anne Heikkonen', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(953) 10956') 78 | GO 79 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (24, N'Sydney', N'G''day, Mate', N'Australia', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(02) 555-4873', N'Wendy Mackenzie', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(02) 555-5914') 80 | GO 81 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (25, N'Montréal', N'Ma Maison', N'Canada', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Jean-Guy Lauzon', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(514) 555-9022') 82 | GO 83 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (26, N'Salerno', N'Pasta Buttini s.r.l.', N'Italy', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(089) 6547667', N'Giovanni Giudici', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(089) 6547665') 84 | GO 85 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (27, N'Montceau', N'Escargots Nouveaux', N'France', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', NULL, N'Marie Delamare', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'85.57.00.07') 86 | GO 87 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (28, N'Annecy', N'Gai pâturage', N'France', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'38.76.98.58', N'Eliane Noz', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'38.76.98.06') 88 | GO 89 | INSERT [dbo].[Suppliers] ([Id], [City], [CompanyName], [Country], [Created], [Email], [Fax], [Manager], [Modified], [Phone]) VALUES (29, N'Ste-Hyacinthe', N'Forêts d''érables', N'Canada', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'company@mail.com', N'(514) 555-2921', N'Chantal Goulet', CAST(N'2017-11-22T13:59:57.0900000' AS DateTime2), N'(514) 555-2955') 90 | GO 91 | SET IDENTITY_INSERT [dbo].[Suppliers] OFF 92 | GO 93 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.DataBase/Northwind.DataBase.sqlproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | Northwind.DataBase 8 | 2.0 9 | 4.1 10 | {fd6dd120-f5d6-4214-bcf6-d03ac2a11a93} 11 | Microsoft.Data.Tools.Schema.Sql.Sql130DatabaseSchemaProvider 12 | Database 13 | 14 | 15 | Northwind.DataBase 16 | Northwind.DataBase 17 | 1033, CI 18 | BySchemaAndSchemaType 19 | True 20 | v4.6.1 21 | CS 22 | Properties 23 | False 24 | True 25 | True 26 | 27 | 28 | bin\Release\ 29 | $(MSBuildProjectName).sql 30 | False 31 | pdbonly 32 | true 33 | false 34 | true 35 | prompt 36 | 4 37 | 38 | 39 | bin\Debug\ 40 | $(MSBuildProjectName).sql 41 | false 42 | true 43 | full 44 | false 45 | true 46 | true 47 | prompt 48 | 4 49 | 50 | 51 | 11.0 52 | 53 | True 54 | 11.0 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Categories/Category.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Products; 2 | using Northwind.Framework; 3 | using Northwind.Framework.Entity; 4 | using System.Collections.Generic; 5 | using System.Collections.ObjectModel; 6 | 7 | namespace Northwind.Domain.Categories 8 | { 9 | public class Category : EntityBase, IEntityKey 10 | { 11 | public Category() 12 | { 13 | _products = new List(); 14 | } 15 | private List _products; 16 | public int Id { get; protected set; } 17 | public string Name { get; protected set; } 18 | public string Description { get; set; } 19 | 20 | public void SetName(string name) 21 | { 22 | TypeCheck.IsNullOrEmpty(name); 23 | Name = name; 24 | } 25 | public virtual ReadOnlyCollection Products { get { return new ReadOnlyCollection(_products); } } 26 | 27 | public static Category Create(string name, string description = "") 28 | { 29 | var category = new Category(); 30 | category.SetName(name); 31 | if (!string.IsNullOrEmpty(description)) 32 | { 33 | category.Description = description; 34 | } 35 | return category; 36 | } 37 | 38 | public void SetId(int id) 39 | { 40 | TypeCheck.IsUsableAsId(id); 41 | Id = id; 42 | } 43 | 44 | public virtual void Add(Product product) 45 | { 46 | _products.Add(product); 47 | //TODO: check product whether exists in another category and change product 48 | //TODO: product added to category 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Categories/ICategoryRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Products; 2 | using Northwind.Framework.Helpers; 3 | using System.Collections.Generic; 4 | 5 | namespace Northwind.Domain.Categories 6 | { 7 | public interface ICategoryRepository : IRepository 8 | { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Customers/Customer.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Orders; 2 | using Northwind.Framework; 3 | using Northwind.Framework.Domain; 4 | using Northwind.Framework.Entity; 5 | using System.Collections.Generic; 6 | 7 | namespace Northwind.Domain.Customers 8 | { 9 | public class Customer : EntityBase, IEntityKey 10 | { 11 | public Customer() 12 | { 13 | _orders = new List(); 14 | } 15 | private List _orders; 16 | public string Id { get; protected set; } 17 | 18 | public string CustomerId { get; protected set; } 19 | public string Title { get; protected set; } 20 | public string Contact { get; protected set; } 21 | public string ContactEMail { get; protected set; } 22 | 23 | public string City { get; set; } 24 | public string Country { get; set; } 25 | 26 | public virtual IReadOnlyCollection Orders => _orders.AsReadOnly(); 27 | public void ChangeCustomerCode(string code) 28 | { 29 | //TODO: check whether customer code exists on database (it is unique) 30 | CustomerId = CustomerPolicy.CheckCustomerCode(TypeCheck.IsNullOrEmpty(code)); 31 | } 32 | 33 | public void SetTitle(string title) 34 | { 35 | Title = TypeCheck.IsNullOrEmpty(title); 36 | } 37 | 38 | public void SetContact(string fullName, string email) 39 | { 40 | TypeCheck.IsNullOrEmpty(fullName); 41 | CommonPolicy.CheckMail(TypeCheck.IsNullOrEmpty(email)); 42 | Contact = fullName; 43 | ContactEMail = email; 44 | 45 | //TODO: Fire an event to notify person about being customer as our customer 46 | } 47 | 48 | public void AddOrder(Order order) 49 | { 50 | _orders.Add(order); 51 | 52 | //TODO: Fire an event to manage other stuffs on creating and order for a customer 53 | } 54 | 55 | public void SetId(string id) 56 | { 57 | TypeCheck.IsNullOrEmpty(id); 58 | Id = id; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Customers/CustomerCodeInvalidException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | using System; 3 | 4 | namespace Northwind.Domain.Customers 5 | { 6 | [Serializable] 7 | internal class CustomerCodeInvalidException : OperationalException 8 | { 9 | public CustomerCodeInvalidException() 10 | { 11 | Type = ExceptionType.InvalidCustomerCode; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Customers/CustomerPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Domain.Customers 6 | { 7 | public class CustomerPolicy 8 | { 9 | public static string CheckCustomerCode(string code) 10 | { 11 | var newValue = code.Trim(); 12 | if (newValue.Length == 0) 13 | throw new CustomerCodeInvalidException(); 14 | return newValue.ToUpper(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Customers/ICustomerRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | 3 | namespace Northwind.Domain.Customers 4 | { 5 | public interface ICustomerRepository : IRepository 6 | { 7 | Customer GetContactByMail(string email); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/Employee.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework; 2 | using Northwind.Framework.Domain; 3 | using Northwind.Framework.Entity; 4 | using System; 5 | 6 | namespace Northwind.Domain.Employees 7 | { 8 | public class Employee : EntityBase, IEntityKey 9 | { 10 | public int Id { get; protected set; } 11 | public string FirstName { get; protected set; } 12 | public string LastName { get; protected set; } 13 | 14 | public DateTime? HireDate { get; set; } 15 | public DateTime? BirthDate { get; set; } 16 | public string EMail { get; protected set; } 17 | public string City { get; set; } 18 | public string Country { get; set; } 19 | public int? ManagerId { get; protected set; } 20 | public static Employee Create(string firstname, string lastname, string email) 21 | { 22 | var employee = new Employee(); 23 | employee.SetName(firstname); 24 | employee.SetLastName(lastname); 25 | employee.SetEMail(email); 26 | employee.Created = DateTime.Now; 27 | employee.Modified = DateTime.Now; 28 | return employee; 29 | } 30 | public void SetName(string name) 31 | { 32 | EmployeePolicy.CheckNameRequirement(name); 33 | FirstName = TypeCheck.IsNullOrEmpty(name); 34 | } 35 | public void SetLastName(string lastname) 36 | { 37 | EmployeePolicy.CheckLastNameRequirement(lastname); 38 | LastName = TypeCheck.IsNullOrEmpty(lastname); 39 | } 40 | 41 | public void SetEMail(string email) 42 | { 43 | CommonPolicy.CheckMail(TypeCheck.IsNullOrEmpty(email)); 44 | EMail = email; 45 | } 46 | 47 | public void SetId(int id) 48 | { 49 | TypeCheck.IsUsableAsId(id); 50 | Id = id; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/EmployeePolicy.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Domain.Employees 2 | { 3 | public class EmployeePolicy 4 | { 5 | public static void CheckNameRequirement(string name) 6 | { 7 | if (name.Length < 3) 8 | throw new NameIsTooShortException(); 9 | } 10 | public static void CheckLastNameRequirement(string name) 11 | { 12 | if (name.Length < 2) 13 | throw new NameIsTooShortException(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/HasManagerFilter.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers.Filters; 2 | using System; 3 | using System.Linq.Expressions; 4 | 5 | namespace Northwind.Domain.Employees 6 | { 7 | public class HasManagerFilter : FilterBase 8 | { 9 | public override Expression> FilterExpression => i => i.ManagerId.HasValue; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/HasNoManagerFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | using Northwind.Framework.Helpers.Filters; 4 | 5 | namespace Northwind.Domain.Employees 6 | { 7 | public class HasNoManagerFilter : FilterBase 8 | { 9 | public override Expression> FilterExpression => i => i.ManagerId.HasValue; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Domain.Employees 5 | { 6 | public interface IEmployeeRepository : IRepository 7 | { 8 | IEnumerable GetEmployeesByCountry(string countryName); 9 | Employee GetManager(int employeeId); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Employees/NameIsTooShortException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | 3 | namespace Northwind.Domain.Employees 4 | { 5 | public class NameIsTooShortException : OperationalException 6 | { 7 | public NameIsTooShortException() 8 | { 9 | Type = ExceptionType.NameIsTooShort; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Northwind.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/OrderDetails/IOrderDetailRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | 3 | namespace Northwind.Domain.OrderDetails 4 | { 5 | public interface IOrderDetailRepository : IRepository 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/OrderDetails/InvalidOrderPriceException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Northwind.Domain.OrderDetails 7 | { 8 | public class InvalidOrderPriceException : OperationalException 9 | { 10 | public InvalidOrderPriceException() 11 | { 12 | Type = ExceptionType.InvalidOrderPriceException; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/OrderDetails/InvalidOrderQuantityException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Northwind.Domain.OrderDetails 7 | { 8 | public class InvalidOrderQuantityException : OperationalException 9 | { 10 | public InvalidOrderQuantityException() 11 | { 12 | Type = ExceptionType.InvalidOrderQuantityException; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/OrderDetails/OrderDetail.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Orders; 2 | using Northwind.Domain.Products; 3 | using Northwind.Framework; 4 | using Northwind.Framework.Entity; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Northwind.Domain.OrderDetails 10 | { 11 | public class OrderDetail : EntityBase, IEntityKey 12 | { 13 | public long Id { get; protected set; } 14 | public long OrderId { get; protected set; } 15 | public long ProductId { get; protected set; } 16 | public double Quantity { get; protected set; } 17 | public double Price { get; protected set; } 18 | public double Discount { get; protected set; } 19 | 20 | public static OrderDetail Create(Product product, Order order, double price, double quantity, double discount = 0) 21 | { 22 | var orderDetail = new OrderDetail(); 23 | TypeCheck.IsNull(product); 24 | TypeCheck.IsUsableAsId(product.Id); 25 | TypeCheck.IsNull(product); 26 | TypeCheck.IsUsableAsId(order.Id); 27 | OrderDetailPolicy.CheckPrice(price); 28 | OrderDetailPolicy.CheckQuantity(quantity); 29 | orderDetail.SetProduct(product.Id); 30 | orderDetail.SetOrder(order.Id); 31 | orderDetail.SetPrice(price); 32 | orderDetail.SetQuantity(quantity); 33 | if(discount > 0) 34 | { 35 | orderDetail.SetDiscount(discount); 36 | } 37 | return orderDetail; 38 | } 39 | 40 | private void SetDiscount(double discount) 41 | { 42 | throw new NotImplementedException(); 43 | } 44 | 45 | private void SetQuantity(double quantity) 46 | { 47 | throw new NotImplementedException(); 48 | } 49 | 50 | private void SetPrice(double price) 51 | { 52 | throw new NotImplementedException(); 53 | } 54 | 55 | private void SetOrder(long id) 56 | { 57 | throw new NotImplementedException(); 58 | } 59 | 60 | private void SetProduct(long id) 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | public void SetId(long id) 66 | { 67 | TypeCheck.IsUsableAsId(id); 68 | Id = id; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/OrderDetails/OrderDetailPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Domain.OrderDetails 6 | { 7 | public class OrderDetailPolicy 8 | { 9 | public static void CheckPrice(double price) 10 | { 11 | if (price <= 0) 12 | throw new InvalidOrderPriceException(); 13 | } 14 | 15 | public static void CheckQuantity(double quantity) 16 | { 17 | if (quantity <= 0) 18 | throw new InvalidOrderQuantityException(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Orders/IOrderRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Northwind.Domain.Orders 7 | { 8 | public interface IOrderRepository : IRepository 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Orders/Order.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Customers; 2 | using Northwind.Domain.Employees; 3 | using Northwind.Framework; 4 | using Northwind.Framework.Entity; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Northwind.Domain.Orders 10 | { 11 | public class Order : EntityBase, IEntityKey 12 | { 13 | public long Id { get; protected set; } 14 | public string CustomerId { get; protected set; } 15 | public int EmployeeId { get; protected set; } 16 | public bool IsUrgent { get; protected set; } 17 | public DateTime? LastShipDate { get; protected set; } 18 | 19 | public static Order Create(Customer customer, Employee employee, bool isUrgent, DateTime? shipDate) 20 | { 21 | TypeCheck.IsNull(customer); 22 | TypeCheck.IsNullOrEmpty(customer.Id); 23 | TypeCheck.IsNull(employee); 24 | TypeCheck.IsUsableAsId(employee.Id); 25 | var order = new Order() { CustomerId = customer.Id, EmployeeId = employee.Id }; 26 | if (isUrgent) 27 | { 28 | order.SetAsUrgent(shipDate); 29 | } 30 | return order; 31 | } 32 | 33 | public void SetAsUrgent(DateTime? shipDate = null) 34 | { 35 | IsUrgent = true; 36 | if (!shipDate.HasValue) 37 | { 38 | LastShipDate = DateTime.Now.AddHours(1);//Domain rule 39 | } 40 | else 41 | { 42 | LastShipDate = DateTime.Now.AddDays(1);//Domain rule 43 | } 44 | 45 | //TODO: Fire event to notify employee on sending this urgent order 46 | } 47 | 48 | public void SetId(long id) 49 | { 50 | TypeCheck.IsUsableAsId(id); 51 | Id = id; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/IProductRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | 3 | namespace Northwind.Domain.Products 4 | { 5 | public interface IProductRepository : IRepository 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/InvalidPriceException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | 3 | namespace Northwind.Domain.Products 4 | { 5 | public class InvalidPriceException : OperationalException 6 | { 7 | public InvalidPriceException() 8 | { 9 | Type = ExceptionType.InvalidPrice; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/InvalidStockException.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain; 2 | using System; 3 | 4 | namespace Northwind.Domain.Products 5 | { 6 | [Serializable] 7 | internal class InvalidStockException : OperationalException 8 | { 9 | public InvalidStockException() 10 | { 11 | Type = ExceptionType.InvalidStock; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/Product.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Categories; 2 | using Northwind.Framework; 3 | using Northwind.Framework.Entity; 4 | using Northwind.Domain.Suppliers; 5 | 6 | namespace Northwind.Domain.Products 7 | { 8 | public class Product : EntityBase, IEntityKey 9 | { 10 | public long Id { get; protected set; } 11 | public string Name { get; protected set; } 12 | public decimal UnitPrice { get; protected set; } 13 | public double UnitsInStock { get; protected set; } 14 | public int CategoryId { get; protected set; } 15 | public int SupplierId { get; protected set; } 16 | 17 | public static Product Create(Category category, Supplier supplier, string name, decimal price, double stock) 18 | { 19 | var product = new Product(); 20 | TypeCheck.IsNull(category); 21 | TypeCheck.IsUsableAsId(category.Id); 22 | TypeCheck.IsNull(supplier); 23 | TypeCheck.IsUsableAsId(supplier.Id); 24 | product.SetCategory(category.Id); 25 | product.SetName(name); 26 | product.SetPrice(price); 27 | product.SetStock(stock); 28 | product.SetSupplier(supplier.Id); 29 | return product; 30 | } 31 | 32 | public static Product CreateSimple(string name, decimal price, double stock) 33 | { 34 | var product = new Product(); 35 | product.SetName(name); 36 | product.SetPrice(price); 37 | product.SetStock(stock); 38 | return product; 39 | } 40 | 41 | private void SetStock(double stock) 42 | { 43 | ProductPolicy.CheckStock(stock); 44 | //TODO: Fire event to notify supplier and sales employee 45 | UnitsInStock = stock; 46 | } 47 | private void SetPrice(decimal price) 48 | { 49 | ProductPolicy.CheckPrice(price); 50 | //TODO: Fire event to notify users for price change 51 | UnitPrice = price; 52 | } 53 | private void SetName(string name) 54 | { 55 | TypeCheck.IsNullOrEmpty(name); 56 | Name = name; 57 | } 58 | public void SetCategory(int id) 59 | { 60 | TypeCheck.IsUsableAsId(id); 61 | CategoryId = id; 62 | } 63 | public void SetSupplier(int id) 64 | { 65 | TypeCheck.IsUsableAsId(id); 66 | //TODO: Fire event to notify supplier on supplying new prouct 67 | SupplierId = id; 68 | } 69 | public void SetId(long id) 70 | { 71 | TypeCheck.IsUsableAsId(id); 72 | Id = id; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/ProductByCategoryFilter.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Categories; 2 | using Northwind.Framework.Helpers.Filters; 3 | using System; 4 | using System.Linq.Expressions; 5 | 6 | namespace Northwind.Domain.Products 7 | { 8 | public class ProductByCategoryFilter : FilterBase 9 | { 10 | private long _categoryId; 11 | public ProductByCategoryFilter(int categoryId) 12 | { 13 | _categoryId = categoryId; 14 | } 15 | public override Expression> FilterExpression => i => i.CategoryId == _categoryId; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Products/ProductPolicy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Domain.Products 6 | { 7 | public class ProductPolicy 8 | { 9 | public static void CheckPrice(decimal price) 10 | { 11 | if (price <= 0) 12 | throw new InvalidPriceException(); 13 | } 14 | 15 | public static void CheckStock(double stock) 16 | { 17 | if (stock <= 0) 18 | throw new InvalidStockException(); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Suppliers/ISupplierRepository.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | 3 | namespace Northwind.Domain.Suppliers 4 | { 5 | public interface ISupplierRepository : IRepository 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Domain/Suppliers/Supplier.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Domain.Products; 2 | using Northwind.Framework; 3 | using Northwind.Framework.Domain; 4 | using Northwind.Framework.Entity; 5 | using System.Collections.Generic; 6 | 7 | namespace Northwind.Domain.Suppliers 8 | { 9 | public class Supplier : EntityBase, IEntityKey 10 | { 11 | public Supplier() 12 | { 13 | _products = new List(); 14 | } 15 | private List _products; 16 | public int Id { get; protected set; } 17 | public string CompanyName { get; protected set; } 18 | public string City { get; set; } 19 | public string Country { get; set; } 20 | public string Manager { get; protected set; } 21 | public string Email { get; protected set; } 22 | public string Phone { get; protected set; } 23 | public string Fax { get; protected set; } 24 | 25 | public virtual IReadOnlyCollection Products => _products.AsReadOnly(); 26 | 27 | public static Supplier Create(string companyName, string manager, string email, string phone) 28 | { 29 | var supplier = new Supplier(); 30 | TypeCheck.IsNullOrEmpty(companyName); 31 | TypeCheck.IsNullOrEmpty(manager); 32 | TypeCheck.IsNullOrEmpty(phone); 33 | supplier.CompanyName = companyName; 34 | supplier.Manager = manager; 35 | supplier.SetMail(email); 36 | supplier.Phone = phone; 37 | return supplier; 38 | } 39 | 40 | public void SetMail(string mail) 41 | { 42 | TypeCheck.IsNullOrEmpty(mail); 43 | CommonPolicy.CheckMail(mail); 44 | //TODO: Fire event to notify supplier about updated mail address 45 | Email = mail; 46 | } 47 | 48 | public void SetId(int id) 49 | { 50 | TypeCheck.IsUsableAsId(id); 51 | Id = id; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/CommonPolicy.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Helpers; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace Northwind.Framework.Domain 5 | { 6 | public class CommonPolicy 7 | { 8 | public static void CheckMail(string mailAddress) 9 | { 10 | var match = Regex.Match(mailAddress, RegexContants.Email); 11 | if (!match.Success) 12 | throw new InvalidEMailException(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/ExceptionType.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Domain 2 | { 3 | public enum ExceptionType 4 | { 5 | NotSet = 0, 6 | NameIsTooShort = 1, 7 | InvalidCharacter = 2, 8 | EmptyValue = 3, 9 | InvalidMailAddress = 4, 10 | InvalidCustomerCode = 5, 11 | InvalidId = 6, 12 | InvalidPrice = 7, 13 | InvalidStock = 8, 14 | InvalidOrderPriceException = 9, 15 | InvalidOrderQuantityException = 10, 16 | EntityNotFoundById = 11 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/Exceptions/Handler/NorthwindExceptionHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using Microsoft.AspNetCore.Mvc.Filters; 3 | using System; 4 | using System.Net; 5 | 6 | namespace Northwind.Framework.Domain.Exceptions 7 | { 8 | public class NorthwindExceptionHandler : IExceptionFilter 9 | { 10 | public void OnException(ExceptionContext context) 11 | { 12 | var status = HttpStatusCode.InternalServerError; 13 | var message = String.Empty; 14 | 15 | var exceptionType = context.Exception.GetType(); 16 | if (exceptionType == typeof(UnauthorizedAccessException)) 17 | { 18 | message = "Unauthorized Access"; 19 | status = HttpStatusCode.Unauthorized; 20 | } 21 | else if (exceptionType == typeof(NotImplementedException)) 22 | { 23 | message = "A server error occurred."; 24 | status = HttpStatusCode.NotImplemented; 25 | } 26 | else if (exceptionType == typeof(OperationalException)) 27 | { 28 | message = context.Exception.ToString(); 29 | status = HttpStatusCode.InternalServerError; 30 | } 31 | else 32 | { 33 | message = context.Exception.Message; 34 | status = HttpStatusCode.NotFound; 35 | } 36 | var response = context.HttpContext.Response; 37 | response.StatusCode = (int)status; 38 | response.ContentType = "application/json"; 39 | var err = message + " " + context.Exception.StackTrace; 40 | response.WriteAsync(err);//TODO : use a different way 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/Exceptions/InvalidEMailException.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Domain 2 | { 3 | public class InvalidEMailException : OperationalException 4 | { 5 | public InvalidEMailException() 6 | { 7 | Type = ExceptionType.InvalidMailAddress; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/Exceptions/InvalidValueAsIdException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Northwind.Framework.Domain.Exceptions 6 | { 7 | public class InvalidValueAsIdException : OperationalException 8 | { 9 | public InvalidValueAsIdException() 10 | { 11 | Type = ExceptionType.InvalidId; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/Exceptions/NotFoundByIdException.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Domain.Exceptions 2 | { 3 | public class NotFoundByIdException : OperationalException 4 | { 5 | public NotFoundByIdException() 6 | { 7 | Type = ExceptionType.EntityNotFoundById; 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/Infrastructure/IDomainService.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Domain 2 | { 3 | /// 4 | /// All business services must be implemented from this interface 5 | /// 6 | public interface IDomainService 7 | { 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Domain/OperationalException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Northwind.Framework.Domain 4 | { 5 | public abstract class OperationalException : Exception 6 | { 7 | public ExceptionType Type { get; set; } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Entity/EntityBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Northwind.Framework.Entity 4 | { 5 | public class EntityBase 6 | { 7 | public DateTime Created { get; set; } 8 | public DateTime Modified { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Entity/IEntityKey.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Entity 2 | { 3 | public interface IEntityKey 4 | { 5 | TKey Id { get; } 6 | void SetId(TKey id); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Constants/RegexContants.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Helpers 2 | { 3 | public struct RegexContants 4 | { 5 | public const string Email = @"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Domain/DomianEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Northwind.Framework.Helpers 5 | { 6 | public abstract class DomainEvent 7 | { 8 | public string Type => GetType().Name; 9 | public DateTime Created { get; private set; } 10 | public Dictionary Parameters { get; private set; } 11 | public string CorrelationID { get; set; } 12 | 13 | public DomainEvent() 14 | { 15 | Created = DateTime.Now; 16 | Parameters = new Dictionary(); 17 | } 18 | public abstract void Simplify(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Domain/IDomainService.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Helpers.Domain 2 | { 3 | public interface IDomainService 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Domain/IEventHandler.cs: -------------------------------------------------------------------------------- 1 | namespace Northwind.Framework.Helpers 2 | { 3 | interface IEventHandler where T : DomainEvent 4 | { 5 | void Handle(T args); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Filters/FilterBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Northwind.Framework.Helpers.Filters 5 | { 6 | public abstract class FilterBase : IFilter 7 | { 8 | private Func _compiledExpression; 9 | private Func CompiledExpression 10 | { 11 | get { return _compiledExpression ?? (_compiledExpression = FilterExpression.Compile()); } 12 | } 13 | public abstract Expression> FilterExpression { get; } 14 | public bool IsFilteredBy(T obj) 15 | { 16 | return CompiledExpression(obj); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Filters/IFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq.Expressions; 3 | 4 | namespace Northwind.Framework.Helpers 5 | { 6 | public interface IFilter 7 | { 8 | Expression> FilterExpression { get; } 9 | bool IsFilteredBy(T obj); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Repository/IRepository.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Northwind.Framework.Entity; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | 7 | namespace Northwind.Framework.Helpers 8 | { 9 | public interface IRepository where TEntity : EntityBase 10 | { 11 | TEntity FindById(TKey id); 12 | TEntity FindSingle(IFilter spec); 13 | IEnumerable Find(IFilter filter); 14 | void Save(TEntity entity); 15 | void Remove(TEntity entity); 16 | DbSet Repository { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Helpers/Repository/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Northwind.Framework.Entity; 3 | using System; 4 | 5 | namespace Northwind.Framework.Helpers 6 | { 7 | public interface IUnitOfWork : IDisposable 8 | { 9 | DbSet GetDbSet() where T : EntityBase; 10 | void Commit(); 11 | void Rollback(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/Northwind.Framework.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll 10 | 11 | 12 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Abstractions.dll 13 | 14 | 15 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore\2.0.0\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Framework/TypeCheck.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Framework.Domain.Exceptions; 2 | using System; 3 | 4 | namespace Northwind.Framework 5 | { 6 | public class TypeCheck 7 | { 8 | public static T IsNull(T value) 9 | { 10 | if (value == null) 11 | throw new ArgumentNullException(nameof(value)); 12 | return value; 13 | } 14 | 15 | public static string IsNullOrEmpty(string value) 16 | { 17 | if (string.IsNullOrEmpty(value)) 18 | throw new ArgumentNullException(nameof(value)); 19 | return value; 20 | } 21 | 22 | public static bool IsUsableAsId(long? number) 23 | { 24 | if (!number.HasValue) 25 | { 26 | return false; 27 | } 28 | if (number <= 0) 29 | throw new InvalidValueAsIdException(); 30 | return true; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.UnitTests/CategoryTest.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Categories; 2 | using Northwind.Domain.Categories; 3 | using System; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System.Collections.Generic; 6 | using System.Text; 7 | using Microsoft.VisualStudio.TestTools.UnitTesting; 8 | using System.Linq; 9 | using Northwind.Domain.Products; 10 | 11 | namespace Northwind.UnitTests 12 | { 13 | [TestClass] 14 | public class CategoryTest : UnitTestBase 15 | { 16 | public CategoryTest() 17 | { 18 | Service = new CategoryManager(UnitOfWork, _resolver.GetService(), _resolver.GetService()); 19 | } 20 | public CategoryManager Service { get; set; } 21 | 22 | [TestMethod] 23 | public void CategoryHasProducts() 24 | { 25 | var category = Service.GetById(1); 26 | var result = Service.HasProducts(category); 27 | Assert.IsTrue(result); 28 | } 29 | 30 | [TestMethod] 31 | public void CategoryProductsCheck() 32 | { 33 | var category = Service.GetById(1); 34 | var result = Service.GetProducts(category).ToList(); 35 | Assert.IsTrue(result.Any() && result.First().Id == 1); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.UnitTests/EmployeeTest.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.TestTools.UnitTesting; 2 | using Northwind.Application.Employees; 3 | using Northwind.Application.Services; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | using Northwind.Domain.Employees; 7 | using System.Linq; 8 | 9 | namespace Northwind.UnitTests 10 | { 11 | [TestClass] 12 | public class EmployeeTest : UnitTestBase 13 | { 14 | public EmployeeTest() 15 | { 16 | Service = new EmployeeManager(_resolver.GetService(), UnitOfWork); 17 | } 18 | public EmployeeManager Service { get; set; } 19 | [TestMethod] 20 | public void GetEmployeeById() 21 | { 22 | var expectedFullName = "Nancy Davolio"; 23 | var employee = Service.GetEmployeeById(1); 24 | var result = $"{employee.FirstName} {employee.LastName}"; 25 | Assert.AreEqual(expectedFullName, result); 26 | } 27 | [TestMethod] 28 | public void AddEmployee() 29 | { 30 | var employee = new EmployeeDto 31 | { 32 | FirstName = "Can", 33 | LastName = "PERK", 34 | EMail = "can.perk@mail.com", 35 | City = "Ankara", 36 | Country = "Turkiye", 37 | BirthDate = new System.DateTime(1988, 2, 8), 38 | HireDate = DateTime.Now.AddDays(-45), 39 | }; 40 | Service.AddEmployee(employee); 41 | UnitOfWork.Commit(); 42 | } 43 | [TestMethod] 44 | public void GetAmericanEmployees() 45 | { 46 | var employees = Service.GetEmployeesByCountry("USA"); 47 | Assert.IsTrue(employees.Any()); 48 | } 49 | [TestMethod] 50 | public void GetEmployeesWhoHasNoManager() 51 | { 52 | var employees = Service.GetEmployeesWithoutManager(); 53 | Assert.IsTrue(employees.Any()); 54 | } 55 | [TestMethod] 56 | public void EmployeeHasManager() 57 | { 58 | var result = Service.UserHasManager(9); 59 | Assert.IsTrue(result); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.UnitTests/Northwind.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.hosting.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Hosting.Abstractions.dll 27 | 28 | 29 | C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http.abstractions\2.0.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.Abstractions.dll 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.UnitTests/UnitTestBase.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Northwind.Application; 5 | using Northwind.Application.Database; 6 | using Northwind.Application.Employees; 7 | using Northwind.Domain.Employees; 8 | using Northwind.Framework.Helpers; 9 | using System; 10 | using System.IO; 11 | 12 | namespace Northwind.UnitTests 13 | { 14 | public abstract class UnitTestBase 15 | { 16 | protected readonly IServiceProvider _resolver; 17 | protected readonly IServiceCollection _services; 18 | public UnitTestBase() 19 | { 20 | _services = new ServiceCollection(); 21 | 22 | var builder = new ConfigurationBuilder() 23 | .SetBasePath(Directory.GetCurrentDirectory()) 24 | .AddJsonFile("appSettings.json", optional: false, reloadOnChange: true) 25 | .AddEnvironmentVariables(); 26 | 27 | var configuration = builder.Build(); 28 | _services.AddDbContext(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection"))); 29 | _services.AddNorthwind(); 30 | _resolver = _services.BuildServiceProvider(); 31 | UnitOfWork = _resolver.GetService(); 32 | } 33 | public IUnitOfWork UnitOfWork { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.UnitTests/appSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=.;Database=NorthwindDomainDriven;Trusted_Connection=True" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace Northwind.Web.Controllers 4 | { 5 | public class HomeController : Controller 6 | { 7 | public IActionResult Index() 8 | { 9 | return View(); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/CategoryViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Categories; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class CategoryViewModel : CategoryDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/CustomerViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Customers; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class CustomerViewModel : CustomerDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/EmployeeViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Employees; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class EmployeeViewModel : EmployeeDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/OrderViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Orders; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class OrderViewModel : OrderDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/ProductViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Products; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class ProductViewModel : ProductDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Models/SupplierViewModel.cs: -------------------------------------------------------------------------------- 1 | using Northwind.Application.Suppliers; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Northwind.Web.Models 8 | { 9 | public class SupplierViewModel : SupplierDto 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Northwind.Web.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | Northwind.Web 6 | Northwind.Web 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace Northwind.Web 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:61563/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Northwind.DDD.Web": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:61564/" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.DependencyInjection; 4 | using Northwind.Application.Database; 5 | using Microsoft.Extensions.Configuration; 6 | using System.IO; 7 | using Microsoft.EntityFrameworkCore; 8 | using Northwind.Application; 9 | using Northwind.Framework.Domain.Exceptions; 10 | 11 | namespace Northwind.Web 12 | { 13 | public class Startup 14 | { 15 | public Startup() 16 | { 17 | var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appSettings.json"); 18 | Configuration = builder.Build(); 19 | } 20 | public IConfigurationRoot Configuration { get; set; } 21 | public void ConfigureServices(IServiceCollection services) 22 | { 23 | services.AddMvc( 24 | config => { 25 | config.Filters.Add(typeof(NorthwindExceptionHandler)); 26 | } 27 | ); 28 | //TODO: Generic injector --> https://horfin.visualstudio.com/Horfin/_versionControl?path=%24%2FHorfin%2FHorfin.Data%2FServiceCollectionExtensions.cs&_a=contents 29 | services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 30 | services.AddNorthwind(); 31 | } 32 | 33 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 34 | { 35 | if (env.IsDevelopment()) 36 | { 37 | app.UseDeveloperExceptionPage(); 38 | } 39 | app.UseStaticFiles(); 40 | app.UseMvcWithDefaultRoute(); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Northwind.DDD/Northwind.Web/appSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=.;Database=NorthwindDomainDriven;Trusted_Connection=True" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Domain Driven Design on Northwind Sample Database 2 | A different version of Northwind Sample Database which was integrated Domain Driven Design. 3 | 4 | Basic features for : 5 |
    6 |
  • Employees
  • 7 |
  • Products
  • 8 |
  • Categories
  • 9 |
  • Suppliers
  • 10 |
  • Orders
  • 11 |
  • Order Details
  • 12 |
  • Customers
  • 13 |
14 | 15 |

Up coming features

16 | 17 | Event Driven Desing will be included to domain methods. 18 | --------------------------------------------------------------------------------