Compare commits
	
		
			19 Commits
		
	
	
		
			main
			...
			developmen
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 585d8883b5 | |||
|   | e9190e6cfa | ||
|   | 87fb83efd3 | ||
|   | c002e7ac1e | ||
| cf344e6eaf | |||
| 571589858a | |||
| 0e1c464cc1 | |||
| b6ca689703 | |||
| eda973287b | |||
| 88ccaea826 | |||
| 73bfcccc9c | |||
| 9cb007399a | |||
| f5c030df01 | |||
|   | 7b1aaacfb5 | ||
| c805ce20a8 | |||
| ad998e0499 | |||
| 8611427557 | |||
| d5aeb0a06e | |||
| 5aa09670bc | 
							
								
								
									
										90
									
								
								AB-API.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								AB-API.sln
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,90 @@ | ||||
|  | ||||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||||
| # Visual Studio Version 17 | ||||
| VisualStudioVersion = 17.4.33205.214 | ||||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.WEB", "AB.WEB\AB.WEB.csproj", "{45855EEB-EA31-476F-A020-1A3B71AD725A}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Domain", "AB.Domain\AB.Domain.csproj", "{9F60492C-A480-4056-983D-0F6B1A1ABD1B}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Services", "AB.Services\AB.Services.csproj", "{74E74C3E-8A8E-4771-894B-A2919B3422E5}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Contracts", "AB.Contracts\AB.Contracts.csproj", "{9319695E-2237-49E2-80CD-761F53364421}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Services.Abstractions", "AB.Services.Abstractions\AB.Services.Abstractions.csproj", "{4E3D1E97-AD83-4F66-825E-105441AF4E15}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Infrastructure", "Infrastructure", "{AD8DD52C-57EC-455A-9A8D-E50009FCE608}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Persistence", "AB.Persistence\AB.Persistence.csproj", "{BF2F36D4-6EF4-43AB-840F-0336EB1723EC}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.API", "AB.API\AB.API.csproj", "{7595A349-8990-467D-8122-8E79931359DC}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{82B06293-18B6-44FF-9D74-18DE555BE86A}" | ||||
| EndProject | ||||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AB.Tests", "AB.Tests\AB.Tests.csproj", "{8FF5BC04-5978-4240-BD91-A65524C35681}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0DF9D27D-42B1-4DD8-9815-60E9D204055F}" | ||||
| EndProject | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solutionFiles", "solutionFiles", "{E62D3C80-1256-4095-ACC3-82F7E6D67D1C}" | ||||
| 	ProjectSection(SolutionItems) = preProject | ||||
| 		.gitignore = .gitignore | ||||
| 		README.md = README.md | ||||
| 	EndProjectSection | ||||
| EndProject | ||||
| Global | ||||
| 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||
| 		Debug|Any CPU = Debug|Any CPU | ||||
| 		Release|Any CPU = Release|Any CPU | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||
| 		{45855EEB-EA31-476F-A020-1A3B71AD725A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{45855EEB-EA31-476F-A020-1A3B71AD725A}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{45855EEB-EA31-476F-A020-1A3B71AD725A}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{45855EEB-EA31-476F-A020-1A3B71AD725A}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{9F60492C-A480-4056-983D-0F6B1A1ABD1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{9F60492C-A480-4056-983D-0F6B1A1ABD1B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{9F60492C-A480-4056-983D-0F6B1A1ABD1B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{9F60492C-A480-4056-983D-0F6B1A1ABD1B}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{74E74C3E-8A8E-4771-894B-A2919B3422E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{74E74C3E-8A8E-4771-894B-A2919B3422E5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{74E74C3E-8A8E-4771-894B-A2919B3422E5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{74E74C3E-8A8E-4771-894B-A2919B3422E5}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{9319695E-2237-49E2-80CD-761F53364421}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{9319695E-2237-49E2-80CD-761F53364421}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{9319695E-2237-49E2-80CD-761F53364421}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{9319695E-2237-49E2-80CD-761F53364421}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{4E3D1E97-AD83-4F66-825E-105441AF4E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{4E3D1E97-AD83-4F66-825E-105441AF4E15}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{4E3D1E97-AD83-4F66-825E-105441AF4E15}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{4E3D1E97-AD83-4F66-825E-105441AF4E15}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{BF2F36D4-6EF4-43AB-840F-0336EB1723EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{BF2F36D4-6EF4-43AB-840F-0336EB1723EC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{BF2F36D4-6EF4-43AB-840F-0336EB1723EC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{BF2F36D4-6EF4-43AB-840F-0336EB1723EC}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{7595A349-8990-467D-8122-8E79931359DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{7595A349-8990-467D-8122-8E79931359DC}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{7595A349-8990-467D-8122-8E79931359DC}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{7595A349-8990-467D-8122-8E79931359DC}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 		{8FF5BC04-5978-4240-BD91-A65524C35681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||
| 		{8FF5BC04-5978-4240-BD91-A65524C35681}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||
| 		{8FF5BC04-5978-4240-BD91-A65524C35681}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||
| 		{8FF5BC04-5978-4240-BD91-A65524C35681}.Release|Any CPU.Build.0 = Release|Any CPU | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(SolutionProperties) = preSolution | ||||
| 		HideSolutionNode = FALSE | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(NestedProjects) = preSolution | ||||
| 		{45855EEB-EA31-476F-A020-1A3B71AD725A} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{9F60492C-A480-4056-983D-0F6B1A1ABD1B} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{74E74C3E-8A8E-4771-894B-A2919B3422E5} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{9319695E-2237-49E2-80CD-761F53364421} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{4E3D1E97-AD83-4F66-825E-105441AF4E15} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{AD8DD52C-57EC-455A-9A8D-E50009FCE608} = {0DF9D27D-42B1-4DD8-9815-60E9D204055F} | ||||
| 		{BF2F36D4-6EF4-43AB-840F-0336EB1723EC} = {AD8DD52C-57EC-455A-9A8D-E50009FCE608} | ||||
| 		{7595A349-8990-467D-8122-8E79931359DC} = {AD8DD52C-57EC-455A-9A8D-E50009FCE608} | ||||
| 		{8FF5BC04-5978-4240-BD91-A65524C35681} = {82B06293-18B6-44FF-9D74-18DE555BE86A} | ||||
| 	EndGlobalSection | ||||
| 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||
| 		SolutionGuid = {C7D1722E-5C50-4F16-BA7D-79977DD1D621} | ||||
| 	EndGlobalSection | ||||
| EndGlobal | ||||
							
								
								
									
										18
									
								
								AB.API/AB.API.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								AB.API/AB.API.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
| 	<PropertyGroup> | ||||
| 		<TargetFramework>net6.0</TargetFramework> | ||||
| 		<ImplicitUsings>enable</ImplicitUsings> | ||||
| 		<Nullable>enable</Nullable> | ||||
| 		<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||||
| 	</PropertyGroup> | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
| 		<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> | ||||
| 	</ItemGroup> | ||||
| 
 | ||||
| 	<ItemGroup> | ||||
| 		<ProjectReference Include="..\AB.Services.Abstractions\AB.Services.Abstractions.csproj" /> | ||||
| 	</ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										12
									
								
								AB.API/AssemblyReference.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								AB.API/AssemblyReference.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.API | ||||
| { | ||||
|     public class AssemblyReference | ||||
|     { | ||||
|     } | ||||
| } | ||||
							
								
								
									
										102
									
								
								AB.API/Controllers/BusinessPartner/CustomerController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								AB.API/Controllers/BusinessPartner/CustomerController.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,102 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Services.Abstractions; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| namespace AB.API.Controllers.BusinessPartner; | ||||
| 
 | ||||
| [ApiController] | ||||
| [Route("api/customers")] | ||||
| [Produces("application/json")] | ||||
| public class CustomerController : ControllerBase | ||||
| { | ||||
| 
 | ||||
|     private readonly ICustomerService _customerService; | ||||
| 
 | ||||
|     public CustomerController(ICustomerService customerService) | ||||
|     { | ||||
|             _customerService = customerService; | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Abrufen aller Kunden  | ||||
|     /// </summary> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns>Eine Liste aller Kunden</returns> | ||||
|     [HttpGet] | ||||
|     public async Task<ActionResult<IEnumerable<CustomerDto>>> GetCustomers(CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customers = await _customerService.GetAllAsync(cancellationToken); | ||||
| 
 | ||||
|         return Ok(customers); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Abrufen eines Kunden anhand seiner Id | ||||
|     /// </summary> | ||||
|     /// <param name="customerId"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns>Den Kunden mit der angegeben Id</returns> | ||||
|     [HttpGet("{customerId:guid}")] | ||||
|     public async Task<ActionResult<CustomerDto>> GetCustomerById(Guid customerId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customer = await _customerService.GetByIdAsync(customerId, cancellationToken); | ||||
| 
 | ||||
|         return Ok(customer); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Anlegen eines neuen Kunden | ||||
|     /// </summary> | ||||
|     /// <param name="customerForCreation"></param> | ||||
|     /// <returns>Einen neu erstellten Kunden</returns> | ||||
|     /// <response code="201">Kunde wurde erstellt</response> | ||||
|     [HttpPost] | ||||
|     [ProducesResponseType(StatusCodes.Status201Created)] | ||||
|     public async Task<CreatedAtActionResult> CreateCustomer([FromBody] CustomerForCreationDto customerForCreation) | ||||
|     { | ||||
|         var customerDto = await _customerService.CreateAsync(customerForCreation); | ||||
| 
 | ||||
|         return CreatedAtAction(nameof(CreateCustomer), new { customerId = customerDto.Id }, customerDto); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Löschen eines vorhandenen Kunden | ||||
|     /// </summary> | ||||
|     /// <param name="customerId"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     /// <response code="204">Kunde wurde gelöscht</response> | ||||
|     /// <response code="404">Kunde wurde nicht gefunden</response> | ||||
|     [HttpDelete("{customerId:guid}")] | ||||
|     [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|     public async Task<NoContentResult> DeleteCustomer(Guid customerId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         await _customerService.DeleteAsync(customerId, cancellationToken); | ||||
| 
 | ||||
|         return NoContent(); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Bearbeiten eines vorhanden Kunden | ||||
|     /// </summary> | ||||
|     /// <param name="customerId"></param> | ||||
|     /// <param name="customerForUpdate"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns>Den veränderten Kunden | ||||
|     /// </returns> | ||||
|     /// <response code="200">Kunde wurde bearbeitet</response> | ||||
|     /// <response code="404">Kunde wurde nicht gefunden</response> | ||||
|     [HttpPut("{customerId:guid}")] | ||||
|     [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|     public async Task<ActionResult<CustomerDto>> UpdateCustomer(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customerDto = await _customerService.UpdateAsync(customerId, customerForUpdate, cancellationToken); | ||||
| 
 | ||||
| 
 | ||||
|         return Ok(customerDto); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										87
									
								
								AB.API/Controllers/BusinessPartner/SupplierController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								AB.API/Controllers/BusinessPartner/SupplierController.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,87 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Services.Abstractions; | ||||
| using Microsoft.AspNetCore.Http; | ||||
| using Microsoft.AspNetCore.Mvc; | ||||
| 
 | ||||
| namespace AB.API.Controllers.BusinessPartner; | ||||
| 
 | ||||
| [ApiController] | ||||
| [Route("api/suppliers")] | ||||
| [Produces("application/json")] | ||||
| public class SupplierController : ControllerBase | ||||
| { | ||||
| 
 | ||||
|     public readonly ISupplierService _supplierService; | ||||
| 
 | ||||
|     public SupplierController(ISupplierService supplierService) | ||||
|     { | ||||
|         _supplierService = supplierService; | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Abrufen aller Lieferanten | ||||
|     /// </summary> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     [HttpGet] | ||||
|     public async Task<ActionResult<IEnumerable<SupplierDto>>> GetSupplieres(CancellationToken cancellationToken) | ||||
|     { | ||||
|         var suppliers = await _supplierService.GetAllAsync(cancellationToken); | ||||
| 
 | ||||
|         return Ok(suppliers); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Abrufen eines Lieferanten anhand seiner Id | ||||
|     /// </summary> | ||||
|     /// <param name="supplierId"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     /// <response code="404">Lieferant wurde nicht gefunden</response> | ||||
|     [HttpGet("{supplierId:guid}")] | ||||
|     [ProducesResponseType(StatusCodes.Status200OK)] | ||||
|     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|     public async Task<ActionResult<SupplierDto>> GetSupplierById(Guid supplierId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var supplierDto = await _supplierService.GetSupplierByIdAsync(supplierId, cancellationToken); | ||||
| 
 | ||||
|         return Ok(supplierDto); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Anlegen eines neuen Lieferanten | ||||
|     /// </summary> | ||||
|     /// <param name="supplierForCreation"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns>Einen neu erstellen Kunden</returns> | ||||
|     /// <response code="201">Lieferant wurde erstellt</response> | ||||
|     [HttpPost] | ||||
|     [ProducesResponseType(StatusCodes.Status201Created)] | ||||
|     public async Task<CreatedAtActionResult> CreateSupplier([FromBody] SupplierForCreationDto supplierForCreation, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var supplierDto = await _supplierService.CreateAsync(supplierForCreation, cancellationToken); | ||||
| 
 | ||||
|         return CreatedAtAction(nameof(CreateSupplier), new { id = supplierDto.Id }, supplierDto); | ||||
|     } | ||||
| 
 | ||||
|     /// <summary> | ||||
|     /// Löschen eines vorhanden Lieferanten | ||||
|     /// </summary> | ||||
|     /// <param name="supplierId"></param> | ||||
|     /// <param name="cancellationToken"></param> | ||||
|     /// <returns></returns> | ||||
|     /// <response code="204">Lieferant wurde gelöscht</response> | ||||
|     /// <response code="404">Lieferant wurde nicht gefunden</response> | ||||
|     [HttpDelete("{supplierId:guid}")] | ||||
|     [ProducesResponseType(StatusCodes.Status204NoContent)] | ||||
|     [ProducesResponseType(StatusCodes.Status404NotFound)] | ||||
|     public async Task<NoContentResult> DeleteSupplier(Guid supplierId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         await _supplierService.DeleteAsync(supplierId, cancellationToken); | ||||
| 
 | ||||
|         return NoContent(); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										9
									
								
								AB.Contracts/AB.Contracts.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								AB.Contracts/AB.Contracts.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										19
									
								
								AB.Contracts/CommunicationType.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								AB.Contracts/CommunicationType.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| using System.Runtime.Serialization; | ||||
| 
 | ||||
| namespace AB.Contracts | ||||
| { | ||||
|     public enum CommunicationType | ||||
|     { | ||||
|         [EnumMember(Value = "Email")] | ||||
|         Email, | ||||
| 
 | ||||
|         [EnumMember(Value = "Postal")] | ||||
|         Postal, | ||||
| 
 | ||||
|         [EnumMember(Value = "Phone")] | ||||
|         Phone, | ||||
| 
 | ||||
|         [EnumMember(Value = "Fax")] | ||||
|         Fax | ||||
|     } | ||||
| } | ||||
							
								
								
									
										16
									
								
								AB.Contracts/ContactPersonDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								AB.Contracts/ContactPersonDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| namespace AB.Contracts; | ||||
| 
 | ||||
| public class ContactPersonDto | ||||
| { | ||||
| 
 | ||||
|     public string Name { get; set; } | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumer { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string Notes { get; set; } | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										19
									
								
								AB.Contracts/CustomerDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								AB.Contracts/CustomerDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| namespace AB.Contracts; | ||||
| 
 | ||||
| public class CustomerDto | ||||
| { | ||||
| 
 | ||||
|     public Guid Id { get; set; } | ||||
| 
 | ||||
|     public string Salutaion { get; set; } | ||||
| 
 | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string Name2 { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string Iban { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| } | ||||
							
								
								
									
										22
									
								
								AB.Contracts/CustomerForCreationDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								AB.Contracts/CustomerForCreationDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| 
 | ||||
| namespace AB.Contracts; | ||||
| 
 | ||||
| public class CustomerForCreationDto | ||||
| { | ||||
|     [Required] | ||||
|     public string Salutaion { get; set; } | ||||
| 
 | ||||
|     [Required] | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string? Name2 { get; set; } | ||||
| 
 | ||||
|     public string? Email { get; set; } | ||||
| 
 | ||||
|     public string? Iban { get; set; } | ||||
| 
 | ||||
|     public string? PhoneNumber { get; set; } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										26
									
								
								AB.Contracts/CustomerForUpdateDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								AB.Contracts/CustomerForUpdateDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.ComponentModel.DataAnnotations; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Contracts | ||||
| { | ||||
|     public class CustomerForUpdateDto | ||||
|     { | ||||
| 
 | ||||
|         public string? Salutaion { get; set; } | ||||
| 
 | ||||
|         public string? Name1 { get; set; } | ||||
| 
 | ||||
|         public string? Name2 { get; set; } | ||||
| 
 | ||||
|         public string? Email { get; set; } | ||||
| 
 | ||||
|         public string? Iban { get; set; } | ||||
| 
 | ||||
|         public string? PhoneNumber { get; set; } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										27
									
								
								AB.Contracts/SupplierDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								AB.Contracts/SupplierDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| using System.Runtime.Serialization; | ||||
| 
 | ||||
| namespace AB.Contracts; | ||||
| 
 | ||||
| public class SupplierDto | ||||
| { | ||||
| 
 | ||||
|     public Guid Id { get; set; } | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string Name2 { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| 
 | ||||
|     public string TaxId { get; set; } | ||||
| 
 | ||||
|     [DataMember(Name = "PreferredCommunication", EmitDefaultValue = true)] | ||||
|     public CommunicationType PreferredCommunication { get; set; } | ||||
| 
 | ||||
|     public IEnumerable<ContactPersonDto> ContactPersons { get; set; } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										27
									
								
								AB.Contracts/SupplierForCreationDto.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								AB.Contracts/SupplierForCreationDto.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| using System.Runtime.Serialization; | ||||
| 
 | ||||
| namespace AB.Contracts; | ||||
| 
 | ||||
| public class SupplierForCreationDto | ||||
| { | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string Name2 { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| 
 | ||||
|     public string TaxId { get; set; } | ||||
| 
 | ||||
|     [DataMember(Name = "PreferredCommunication", EmitDefaultValue = true)] | ||||
|     public CommunicationType PreferredCommunication { get; set; } | ||||
| 
 | ||||
|     public IEnumerable<ContactPersonDto> ContactPersons { get; set; } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										9
									
								
								AB.Domain/AB.Domain.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								AB.Domain/AB.Domain.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										11
									
								
								AB.Domain/Entities/CommunicationType.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								AB.Domain/Entities/CommunicationType.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| namespace AB.Domain.Enums | ||||
| { | ||||
|     public enum CommunicationType | ||||
|     { | ||||
|         Email, | ||||
|         Postal, | ||||
|         Phone, | ||||
|         Fax | ||||
| 
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										20
									
								
								AB.Domain/Entities/ContactPerson.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								AB.Domain/Entities/ContactPerson.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| namespace AB.Domain.Entities; | ||||
| 
 | ||||
| public class ContactPerson | ||||
| { | ||||
| 
 | ||||
|     public Guid ContactPersonId { get; set; } | ||||
| 
 | ||||
|     public Guid SupplierId { get; set; } | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string Name { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string Notes { get; set; } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										26
									
								
								AB.Domain/Entities/Customer.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								AB.Domain/Entities/Customer.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Entities; | ||||
| 
 | ||||
| public class Customer | ||||
| {  | ||||
| 
 | ||||
|     public Guid CustomerId { get; set; } | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string Name2 { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string Iban { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										13
									
								
								AB.Domain/Entities/Product.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								AB.Domain/Entities/Product.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Entities; | ||||
| 
 | ||||
| public class Product | ||||
| { | ||||
|     public Guid ProductId { get; set; } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										30
									
								
								AB.Domain/Entities/Supplier.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								AB.Domain/Entities/Supplier.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,30 @@ | ||||
| using AB.Domain.Enums; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Entities; | ||||
| 
 | ||||
| public class Supplier | ||||
| { | ||||
| 
 | ||||
|     public Guid SupplierId { get; set; } | ||||
| 
 | ||||
|     public string Salutation { get; set; } | ||||
| 
 | ||||
|     public string Name1 { get; set; } | ||||
| 
 | ||||
|     public string Name2 { get; set; } | ||||
| 
 | ||||
|     public string Email { get; set; } | ||||
| 
 | ||||
|     public string PhoneNumber { get; set; } | ||||
| 
 | ||||
|     public string TaxId { get; set; } | ||||
| 
 | ||||
|     public CommunicationType PreferredCommunication { get; set; } | ||||
| 
 | ||||
|     public List<ContactPerson> ContactPersons { get; set; } | ||||
| } | ||||
							
								
								
									
										16
									
								
								AB.Domain/Exceptions/BusinessPartnerNotFoundException.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								AB.Domain/Exceptions/BusinessPartnerNotFoundException.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Exceptions; | ||||
| 
 | ||||
| public class BusinessPartnerNotFoundException : NotFoundException | ||||
| { | ||||
| 
 | ||||
|     public BusinessPartnerNotFoundException(Guid businessPartnerId) | ||||
|     : base ($"The BusinessPartner with the indetifier {businessPartnerId} was not found.") | ||||
|         { } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										19
									
								
								AB.Domain/Exceptions/NotFoundException.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								AB.Domain/Exceptions/NotFoundException.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Exceptions; | ||||
| 
 | ||||
| 
 | ||||
| [Serializable] | ||||
| public abstract class NotFoundException : Exception | ||||
| { | ||||
| 	public NotFoundException() { } | ||||
| 	public NotFoundException(string message) : base(message) { } | ||||
| 	public NotFoundException(string message, Exception inner) : base(message, inner) { } | ||||
| 	protected NotFoundException( | ||||
| 	  System.Runtime.Serialization.SerializationInfo info, | ||||
| 	  System.Runtime.Serialization.StreamingContext context) : base(info, context) { } | ||||
| } | ||||
							
								
								
									
										16
									
								
								AB.Domain/Repositories/ICustomerRepository.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								AB.Domain/Repositories/ICustomerRepository.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| using AB.Domain.Entities; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Domain.Repositories; | ||||
| 
 | ||||
| public interface ICustomerRepository | ||||
| { | ||||
|     public Task<IEnumerable<Customer>> GetAllAsync(CancellationToken cancellationToken); | ||||
|     public Task<Customer> GetByIdAsync(Guid customerId, CancellationToken cancellationToken); | ||||
|     public void Insert(Customer customer); | ||||
|     public void Remove(Customer customer); | ||||
| } | ||||
							
								
								
									
										11
									
								
								AB.Domain/Repositories/ISupplierRepository.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								AB.Domain/Repositories/ISupplierRepository.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| using AB.Domain.Entities; | ||||
| 
 | ||||
| namespace AB.Domain.Repositories; | ||||
| 
 | ||||
| public interface ISupplierRepository | ||||
| { | ||||
|     public Task<IEnumerable<Supplier>> GetAllAsync(CancellationToken cancellationToken); | ||||
|     public Task<Supplier> GetByIdAsync(Guid supplierId, CancellationToken cancellationToken); | ||||
|     public void Insert(Supplier supplier); | ||||
|     public void Remove(Supplier supplier); | ||||
| } | ||||
							
								
								
									
										6
									
								
								AB.Domain/Repositories/IUnitOfWork.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								AB.Domain/Repositories/IUnitOfWork.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| namespace AB.Domain.Repositories; | ||||
| 
 | ||||
| public interface IUnitOfWork | ||||
| { | ||||
|     public Task<int> SaveChangesAsync(CancellationToken cancellationToken); | ||||
| } | ||||
							
								
								
									
										17
									
								
								AB.Persistence/AB.Persistence.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								AB.Persistence/AB.Persistence.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\AB.Domain\AB.Domain.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										22
									
								
								AB.Persistence/RepoDbContext.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								AB.Persistence/RepoDbContext.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,22 @@ | ||||
| using AB.Domain.Entities; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| 
 | ||||
| namespace AB.Persistence; | ||||
| 
 | ||||
| public sealed class RepoDbContext : DbContext | ||||
| { | ||||
| 
 | ||||
|     public RepoDbContext(DbContextOptions options) | ||||
|         : base(options) | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     public DbSet<Customer> Customers { get; set; } | ||||
| 
 | ||||
|     public DbSet<Supplier> Suppliers { get; set; } | ||||
| 
 | ||||
|     public DbSet<ContactPerson> ContactPersons { get; set; } | ||||
| 
 | ||||
|     public DbSet<Product> Products { get; set; } | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										36
									
								
								AB.Persistence/Repos/CustomerRepository.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								AB.Persistence/Repos/CustomerRepository.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | ||||
| using AB.Domain.Entities; | ||||
| using AB.Domain.Repositories; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| 
 | ||||
| namespace AB.Persistence.Repos; | ||||
| 
 | ||||
| public class CustomerRepository : ICustomerRepository | ||||
| { | ||||
| 
 | ||||
|     private readonly RepoDbContext _dbContext; | ||||
| 
 | ||||
|     public CustomerRepository(RepoDbContext dbContext) | ||||
|     { | ||||
|         _dbContext = dbContext; | ||||
|     } | ||||
| 
 | ||||
|     public async Task<IEnumerable<Customer>> GetAllAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         return await _dbContext.Customers.ToListAsync(cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     public async Task<Customer> GetByIdAsync(Guid customerId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         return await _dbContext.Customers.FirstOrDefaultAsync(x => x.CustomerId == customerId, cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     public void Insert(Customer customer) | ||||
|     { | ||||
|         _dbContext.Customers.Add(customer); | ||||
|     } | ||||
| 
 | ||||
|     public void Remove(Customer customer) | ||||
|     { | ||||
|         _dbContext.Customers.Remove(customer); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										41
									
								
								AB.Persistence/Repos/SupplierRepository.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								AB.Persistence/Repos/SupplierRepository.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,41 @@ | ||||
| using AB.Domain.Entities; | ||||
| using AB.Domain.Repositories; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Persistence.Repos; | ||||
| 
 | ||||
| public class SupplierRepository : ISupplierRepository | ||||
| { | ||||
|     private readonly RepoDbContext _dbContext; | ||||
| 
 | ||||
|     public SupplierRepository(RepoDbContext dbContext) | ||||
|     { | ||||
|         _dbContext = dbContext; | ||||
|     } | ||||
| 
 | ||||
|     public async Task<IEnumerable<Supplier>> GetAllAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         return await _dbContext.Suppliers.Include(x => x.ContactPersons).ToListAsync(cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     public async Task<Supplier> GetByIdAsync(Guid supplierId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         return await _dbContext.Suppliers.Include(x => x.ContactPersons).FirstOrDefaultAsync(x => x.SupplierId == supplierId, cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     public void Insert(Supplier supplier) | ||||
|     { | ||||
|         _dbContext.Add(supplier); | ||||
|     } | ||||
| 
 | ||||
|     public void Remove(Supplier supplier) | ||||
|     { | ||||
|          | ||||
|         _dbContext.Suppliers.Remove(supplier); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										19
									
								
								AB.Persistence/Repos/UnitOfWork.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								AB.Persistence/Repos/UnitOfWork.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| using AB.Domain.Repositories; | ||||
| 
 | ||||
| namespace AB.Persistence.Repos; | ||||
| 
 | ||||
| public class UnitOfWork : IUnitOfWork | ||||
| { | ||||
| 
 | ||||
|     private readonly RepoDbContext _dbContext; | ||||
| 
 | ||||
|     public UnitOfWork(RepoDbContext dbContext) | ||||
|     { | ||||
|         _dbContext = dbContext; | ||||
|     } | ||||
| 
 | ||||
|     public Task<int> SaveChangesAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         return _dbContext.SaveChangesAsync(cancellationToken); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										13
									
								
								AB.Services.Abstractions/AB.Services.Abstractions.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								AB.Services.Abstractions/AB.Services.Abstractions.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\AB.Contracts\AB.Contracts.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										17
									
								
								AB.Services.Abstractions/ICustomerService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								AB.Services.Abstractions/ICustomerService.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,17 @@ | ||||
| using AB.Contracts; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Services.Abstractions; | ||||
| 
 | ||||
| public interface ICustomerService | ||||
| { | ||||
|     Task<CustomerDto> CreateAsync(CustomerForCreationDto customerForCreation, CancellationToken cancellationToken = default); | ||||
|     Task DeleteAsync(Guid customerId, CancellationToken cancellationToken); | ||||
|     Task<IEnumerable<CustomerDto>> GetAllAsync(CancellationToken cancellationToken); | ||||
|     Task<CustomerDto> GetByIdAsync(Guid customerId, CancellationToken cancellationToken); | ||||
|     Task<CustomerDto> UpdateAsync(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken); | ||||
| } | ||||
							
								
								
									
										11
									
								
								AB.Services.Abstractions/ISupplierService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								AB.Services.Abstractions/ISupplierService.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,11 @@ | ||||
| using AB.Contracts; | ||||
| 
 | ||||
| namespace AB.Services.Abstractions; | ||||
| 
 | ||||
| public interface ISupplierService | ||||
| { | ||||
|     public Task<SupplierDto> CreateAsync(SupplierForCreationDto supplierForCreation, CancellationToken cancellationToken); | ||||
|     public Task DeleteAsync(Guid supplierId, CancellationToken cancellationToken); | ||||
|     public Task<IEnumerable<SupplierDto>> GetAllAsync(CancellationToken cancellationToken); | ||||
|     public Task<SupplierDto> GetSupplierByIdAsync(Guid supplierId, CancellationToken cancellationToken); | ||||
| } | ||||
							
								
								
									
										14
									
								
								AB.Services/AB.Services.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								AB.Services/AB.Services.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\AB.Domain\AB.Domain.csproj" /> | ||||
|     <ProjectReference Include="..\AB.Services.Abstractions\AB.Services.Abstractions.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										54
									
								
								AB.Services/Converter/CommunicationTypeConverter.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								AB.Services/Converter/CommunicationTypeConverter.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| using AB.Contracts; | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| 
 | ||||
| namespace AB.Services.Converter; | ||||
| 
 | ||||
| internal class CommunicationTypeConverter | ||||
| { | ||||
| 
 | ||||
|     public static CommunicationType ConvertFromBusinessValue | ||||
|         (Domain.Enums.CommunicationType communicationType) | ||||
|     { | ||||
|         switch (communicationType) | ||||
|         { | ||||
|             case Domain.Enums.CommunicationType.Email: | ||||
|                 return CommunicationType.Email; | ||||
|             case Domain.Enums.CommunicationType.Phone: | ||||
|                 return CommunicationType.Phone; | ||||
|             case Domain.Enums.CommunicationType.Postal: | ||||
|                 return CommunicationType.Postal; | ||||
|             case Domain.Enums.CommunicationType.Fax: | ||||
|                 return CommunicationType.Fax; | ||||
|             default: | ||||
|                 var ex = new ArgumentException( | ||||
|                 $"Invalid Type of {nameof(Domain.Enums.CommunicationType)}: {communicationType}", | ||||
|                 nameof(communicationType)); | ||||
|                 throw ex; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static Domain.Enums.CommunicationType ConvertToBusinessValue | ||||
|         (CommunicationType communicationType) | ||||
|     { | ||||
|         switch (communicationType) | ||||
|         { | ||||
|             case CommunicationType.Email: | ||||
|                 return Domain.Enums.CommunicationType.Email; | ||||
|             case CommunicationType.Postal: | ||||
|                 return Domain.Enums.CommunicationType.Postal; | ||||
|             case CommunicationType.Fax: | ||||
|                 return Domain.Enums.CommunicationType.Fax; | ||||
|             case CommunicationType.Phone: | ||||
|                 return Domain.Enums.CommunicationType.Phone; | ||||
|             default: | ||||
|                 var ex = new ArgumentException( | ||||
|                 $"Invalid Type of {nameof(Domain.Enums.CommunicationType)}: {communicationType}", | ||||
|                 nameof(communicationType)); | ||||
|                 throw ex; | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										44
									
								
								AB.Services/Converter/ContactPersonConverter.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								AB.Services/Converter/ContactPersonConverter.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Domain.Entities; | ||||
| 
 | ||||
| namespace AB.Services.Converter; | ||||
| 
 | ||||
| internal static class ContactPersonConverter | ||||
| { | ||||
| 
 | ||||
|     public static ContactPersonDto ConvertToDto(this ContactPerson contactPerson) | ||||
|     { | ||||
|         var dto = new ContactPersonDto | ||||
|         { | ||||
|             Salutation = contactPerson.Salutation, | ||||
|             Name = contactPerson.Name, | ||||
|             Email = contactPerson.Email, | ||||
|             PhoneNumer = contactPerson.PhoneNumber, | ||||
|             Notes = contactPerson.Notes, | ||||
|         }; | ||||
|         return dto; | ||||
|     } | ||||
| 
 | ||||
|     public static ContactPerson ConvertToBusinessType(this ContactPersonDto dto) | ||||
|     { | ||||
|         var contactPerson = new ContactPerson | ||||
|         { | ||||
|             Salutation = dto.Salutation, | ||||
|             Name = dto.Name, | ||||
|             Email = dto.Email, | ||||
|             PhoneNumber = dto.PhoneNumer, | ||||
|             Notes = dto.Notes, | ||||
|         }; | ||||
|         return contactPerson; | ||||
|     } | ||||
| 
 | ||||
|     public static List<ContactPerson> ConvertToContactPersonList(this IEnumerable<ContactPersonDto> contactPersons) | ||||
|     { | ||||
|         return contactPersons.Select(x => x.ConvertToBusinessType()).ToList(); | ||||
|     } | ||||
| 
 | ||||
|     public static IEnumerable<ContactPersonDto> ConvertToContactPersonDtoList(this List<ContactPerson> contactPersons) | ||||
|     { | ||||
|         return contactPersons.Select(x => x.ConvertToDto()); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										130
									
								
								AB.Services/CustomerService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										130
									
								
								AB.Services/CustomerService.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,130 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Domain.Entities; | ||||
| using AB.Domain.Exceptions; | ||||
| using AB.Domain.Repositories; | ||||
| using AB.Services.Abstractions; | ||||
| 
 | ||||
| namespace AB.Services; | ||||
| 
 | ||||
| public class CustomerService : ICustomerService | ||||
| { | ||||
| 
 | ||||
|     private readonly ICustomerRepository _customerRepository; | ||||
| 
 | ||||
|     private readonly IUnitOfWork _unitOfWork; | ||||
| 
 | ||||
|     public CustomerService(ICustomerRepository customerRepository, IUnitOfWork unitOfWork) | ||||
|     { | ||||
|         _customerRepository = customerRepository; | ||||
|         _unitOfWork = unitOfWork; | ||||
|     } | ||||
| 
 | ||||
|     public async Task<CustomerDto> CreateAsync(CustomerForCreationDto customerForCreation, CancellationToken cancellationToken = default) | ||||
|     { | ||||
|         var customer = new Customer | ||||
|         { | ||||
|             Salutation = customerForCreation.Salutaion, | ||||
|             Name1 = customerForCreation.Name1, | ||||
|             Name2 = (customerForCreation.Name2 is null) ? string.Empty : customerForCreation.Name2, | ||||
|             Email = (customerForCreation.Email is null) ? string.Empty : customerForCreation.Email, | ||||
|             PhoneNumber = (customerForCreation.PhoneNumber is null) ? string.Empty : customerForCreation.PhoneNumber, | ||||
|             Iban = (customerForCreation.Iban is null) ? string.Empty : customerForCreation.Iban, | ||||
|         }; | ||||
| 
 | ||||
|         _customerRepository.Insert(customer); | ||||
| 
 | ||||
|         await _unitOfWork.SaveChangesAsync(cancellationToken); | ||||
| 
 | ||||
|         var customerDto = ConvertToCustomerDto(customer); | ||||
| 
 | ||||
|         return customerDto; | ||||
|     } | ||||
| 
 | ||||
|     public async Task DeleteAsync(Guid customerId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customer = await _customerRepository.GetByIdAsync(customerId, cancellationToken); | ||||
| 
 | ||||
|         if (customer is null) | ||||
|         { | ||||
|             throw new BusinessPartnerNotFoundException(customerId); | ||||
|         } | ||||
| 
 | ||||
|         _customerRepository.Remove(customer); | ||||
| 
 | ||||
|         await _unitOfWork.SaveChangesAsync(cancellationToken); | ||||
|     } | ||||
| 
 | ||||
|     public async Task<IEnumerable<CustomerDto>> GetAllAsync(CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customers = await _customerRepository.GetAllAsync(cancellationToken); | ||||
| 
 | ||||
|         var customerDtoList = customers.Select(customer => | ||||
|         { | ||||
|             return ConvertToCustomerDto(customer); | ||||
|         }); | ||||
| 
 | ||||
|         return customerDtoList; | ||||
|     } | ||||
| 
 | ||||
|     public async Task<CustomerDto> GetByIdAsync(Guid customerId, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customer = await _customerRepository.GetByIdAsync(customerId, cancellationToken); | ||||
| 
 | ||||
|         if (customer is null) | ||||
|         { | ||||
|             throw new BusinessPartnerNotFoundException(customerId); | ||||
|         } | ||||
| 
 | ||||
|         var customerDto = ConvertToCustomerDto(customer); | ||||
| 
 | ||||
|         return customerDto; | ||||
|     } | ||||
| 
 | ||||
|     public async Task<CustomerDto> UpdateAsync(Guid customerId, CustomerForUpdateDto customerForUpdate, CancellationToken cancellationToken) | ||||
|     { | ||||
|         var customer = await _customerRepository.GetByIdAsync(customerId, cancellationToken); | ||||
| 
 | ||||
|         if (customer is null) | ||||
|         { | ||||
|             throw new BusinessPartnerNotFoundException(customerId); | ||||
|         } | ||||
| 
 | ||||
|         SetIfContains(customerForUpdate.Salutaion, customer, nameof(customer.Salutation)); | ||||
|         SetIfContains(customerForUpdate.Name1, customer, nameof(customer.Name1)); | ||||
|         SetIfContains(customerForUpdate.Name2, customer, nameof(customer.Name2)); | ||||
|         SetIfContains(customerForUpdate.Email, customer, nameof(customer.Email)); | ||||
|         SetIfContains(customerForUpdate.Iban, customer, nameof(customer.Iban)); | ||||
|         SetIfContains(customerForUpdate.PhoneNumber, customer, nameof(customer.PhoneNumber)); | ||||
| 
 | ||||
|         await _unitOfWork.SaveChangesAsync(cancellationToken); | ||||
| 
 | ||||
|         var customerDto = ConvertToCustomerDto(customer); | ||||
| 
 | ||||
|         return customerDto; | ||||
|     } | ||||
| 
 | ||||
|     private static CustomerDto ConvertToCustomerDto(Customer customer) | ||||
|     { | ||||
|         var customerDto = new CustomerDto | ||||
|         { | ||||
|             Id = customer.CustomerId, | ||||
|             Salutaion = customer.Salutation, | ||||
|             Name1 = customer.Name1, | ||||
|             Name2 = customer.Name2, | ||||
|             Email = customer.Email, | ||||
|             PhoneNumber = customer.PhoneNumber, | ||||
|             Iban = customer.Iban, | ||||
|         }; | ||||
|         return customerDto; | ||||
|     } | ||||
| 
 | ||||
|     public static void SetIfContains<T>(T value, Customer customer, string propertyName) | ||||
|     { | ||||
|         if (value is not null && !string.IsNullOrWhiteSpace(propertyName)) | ||||
|         { | ||||
|             customer.GetType().GetProperty(propertyName).SetValue(customer, value); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										100
									
								
								AB.Services/SupplierService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								AB.Services/SupplierService.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,100 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Domain.Entities; | ||||
| using AB.Domain.Exceptions; | ||||
| using AB.Domain.Repositories; | ||||
| using AB.Services.Abstractions; | ||||
| using AB.Services.Converter; | ||||
| 
 | ||||
| namespace AB.Services | ||||
| { | ||||
|     public class SupplierService : ISupplierService | ||||
|     { | ||||
| 
 | ||||
|         private readonly ISupplierRepository _supplierRepository; | ||||
| 
 | ||||
|         private readonly IUnitOfWork _unitOfWork; | ||||
| 
 | ||||
|         public SupplierService(ISupplierRepository supplierRepository, IUnitOfWork unitOfWork) | ||||
|         { | ||||
|             _supplierRepository = supplierRepository; | ||||
|             _unitOfWork = unitOfWork; | ||||
|         } | ||||
| 
 | ||||
|         public async Task<SupplierDto> CreateAsync(SupplierForCreationDto supplierForCreation, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var supplier = new Supplier | ||||
|             { | ||||
|                 Salutation = supplierForCreation.Salutation, | ||||
|                 Name1 = supplierForCreation.Name1, | ||||
|                 Name2 = supplierForCreation.Name2, | ||||
|                 Email = supplierForCreation.Email, | ||||
|                 PhoneNumber = supplierForCreation.PhoneNumber, | ||||
|                 TaxId = supplierForCreation.TaxId, | ||||
|                 PreferredCommunication = CommunicationTypeConverter.ConvertToBusinessValue(supplierForCreation.PreferredCommunication), | ||||
|                 ContactPersons = supplierForCreation.ContactPersons.ConvertToContactPersonList(), | ||||
|             }; | ||||
| 
 | ||||
|             _supplierRepository.Insert(supplier); | ||||
| 
 | ||||
|             await _unitOfWork.SaveChangesAsync(cancellationToken); | ||||
| 
 | ||||
|             var supplierDto = ConvertToSupplierDto(supplier); | ||||
| 
 | ||||
|             return supplierDto; | ||||
|         } | ||||
| 
 | ||||
|         public async Task DeleteAsync(Guid supplierId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var supplier = await _supplierRepository.GetByIdAsync(supplierId, cancellationToken); | ||||
| 
 | ||||
|             if (supplier is null) | ||||
|             { | ||||
|                 throw new BusinessPartnerNotFoundException(supplierId); | ||||
|             } | ||||
| 
 | ||||
|             _supplierRepository.Remove(supplier); | ||||
| 
 | ||||
|             await _unitOfWork.SaveChangesAsync(cancellationToken); | ||||
|         } | ||||
| 
 | ||||
|         public async Task<IEnumerable<SupplierDto>> GetAllAsync(CancellationToken cancellationToken) | ||||
|         { | ||||
|             var supplierList = await _supplierRepository.GetAllAsync(cancellationToken); | ||||
| 
 | ||||
|             var supplierDtoList = supplierList.Select(supplier => | ||||
|             { | ||||
|                 return ConvertToSupplierDto(supplier); | ||||
|             }); | ||||
| 
 | ||||
|             return supplierDtoList; | ||||
|         } | ||||
| 
 | ||||
|         public async Task<SupplierDto> GetSupplierByIdAsync(Guid supplierId, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var supplier = await _supplierRepository.GetByIdAsync(supplierId, cancellationToken); | ||||
| 
 | ||||
|             var supplierDto = ConvertToSupplierDto(supplier); | ||||
| 
 | ||||
|             return supplierDto; | ||||
|         } | ||||
| 
 | ||||
|         private SupplierDto ConvertToSupplierDto(Supplier supplier) | ||||
|         { | ||||
|             var supplierDto = new SupplierDto | ||||
|             { | ||||
|                 Id = supplier.SupplierId, | ||||
|                 Salutation = supplier.Salutation, | ||||
|                 Name1 = supplier.Name1, | ||||
|                 Name2 = supplier.Name2, | ||||
|                 Email = supplier.Email, | ||||
|                 PhoneNumber = supplier.PhoneNumber, | ||||
|                 TaxId = supplier.TaxId, | ||||
|                 PreferredCommunication = CommunicationTypeConverter.ConvertFromBusinessValue(supplier.PreferredCommunication), | ||||
|                 ContactPersons = supplier.ContactPersons.ConvertToContactPersonDtoList(), | ||||
|             }; | ||||
|             return supplierDto; | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										31
									
								
								AB.Tests/AB.Tests.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								AB.Tests/AB.Tests.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <Nullable>enable</Nullable> | ||||
| 
 | ||||
|     <IsPackable>false</IsPackable> | ||||
|     <IsTestProject>true</IsTestProject> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||||
|     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||||
|     <PackageReference Include="Moq" Version="4.18.4" /> | ||||
|     <PackageReference Include="xunit" Version="2.4.2" /> | ||||
|     <PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||||
|       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||
|       <PrivateAssets>all</PrivateAssets> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="coverlet.collector" Version="3.2.0"> | ||||
|       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||
|       <PrivateAssets>all</PrivateAssets> | ||||
|     </PackageReference> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\AB.Services\AB.Services.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										105
									
								
								AB.Tests/CustomerTests.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										105
									
								
								AB.Tests/CustomerTests.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,105 @@ | ||||
| using AB.Contracts; | ||||
| using AB.Domain.Entities; | ||||
| using AB.Domain.Exceptions; | ||||
| using AB.Domain.Repositories; | ||||
| using AB.Services; | ||||
| 
 | ||||
| namespace AB.Tests | ||||
| { | ||||
|     public class CustomerTests | ||||
|     { | ||||
| 
 | ||||
|         private readonly Mock<IUnitOfWork> _unitOfWorkMock = new Mock<IUnitOfWork>(); | ||||
| 
 | ||||
|         private readonly Mock<ICustomerRepository> _customerRepositoryMock = new Mock<ICustomerRepository>(); | ||||
| 
 | ||||
|         [Fact] | ||||
|         public async void TestCreateCustomer_Sucess() | ||||
|         { | ||||
|             var customerService = new CustomerService(_customerRepositoryMock.Object, _unitOfWorkMock.Object); | ||||
| 
 | ||||
|             var customerForCreationDto = new CustomerForCreationDto | ||||
|             { | ||||
|                 Salutaion = "Firma", | ||||
|                 Name1 = "Arik Meyer", | ||||
|                 Email = "test@test.de", | ||||
|                 PhoneNumber = "1234567890", | ||||
|                 Iban = "DE12345890", | ||||
|             }; | ||||
| 
 | ||||
|             var customerDto = await customerService.CreateAsync(customerForCreationDto); | ||||
| 
 | ||||
|             customerDto.Salutaion.Should().Be(customerForCreationDto.Salutaion); | ||||
|             customerDto.Name1.Should().Be(customerForCreationDto.Name1); | ||||
|             customerDto.Email.Should().Be(customerForCreationDto.Email); | ||||
|             customerDto.PhoneNumber.Should().Be(customerForCreationDto.PhoneNumber); | ||||
|             customerDto.Iban.Should().Be(customerForCreationDto.Iban); | ||||
|         } | ||||
| 
 | ||||
|         [Fact] | ||||
|         private async void TestGetCustomers_Sucess() | ||||
|         { | ||||
|             CancellationToken cancellationToken = default; | ||||
| 
 | ||||
|             var customerList = new List<Customer>  | ||||
|             { | ||||
|                 new Customer | ||||
|                 { | ||||
|                     CustomerId = Guid.NewGuid(), | ||||
|                     Salutation = "Herr", | ||||
|                 }, | ||||
|                 new Customer | ||||
|                 { | ||||
|                     CustomerId = Guid.NewGuid(), | ||||
|                     Name1 = "Peter Sprudel" | ||||
|                 } | ||||
| 
 | ||||
|             }; | ||||
| 
 | ||||
|             _customerRepositoryMock.Setup(repo => repo.GetAllAsync(cancellationToken)).ReturnsAsync(customerList); | ||||
| 
 | ||||
|             var customerService = new CustomerService(_customerRepositoryMock.Object, _unitOfWorkMock.Object); | ||||
| 
 | ||||
|             var dtoList = await customerService.GetAllAsync(cancellationToken); | ||||
| 
 | ||||
|             dtoList.Should().NotBeNullOrEmpty(); | ||||
| 
 | ||||
|             dtoList.ElementAt(0).Salutaion.Should().Be(customerList[0].Salutation); | ||||
|             dtoList.ElementAt(0).Id.Should().Be(customerList[0].CustomerId); | ||||
| 
 | ||||
|             dtoList.ElementAt(1).Name1.Should().Be(customerList[1].Name1); | ||||
|             dtoList.ElementAt(1).Id.Should().Be(customerList[1].CustomerId); | ||||
|         } | ||||
| 
 | ||||
|         [Fact] | ||||
|         private async void TestGetCustomerById_Exception() | ||||
|         { | ||||
|             var id = Guid.NewGuid(); | ||||
|             CancellationToken cancellationToken = default; | ||||
|             _customerRepositoryMock.Setup(repo => repo.GetByIdAsync(id, cancellationToken)).ThrowsAsync(new BusinessPartnerNotFoundException(id)); | ||||
| 
 | ||||
|             var customerService = new CustomerService(_customerRepositoryMock.Object, _unitOfWorkMock.Object); | ||||
| 
 | ||||
|             var exec = () =>  customerService.GetByIdAsync(id, cancellationToken); | ||||
| 
 | ||||
|             await exec.Should().ThrowExactlyAsync<BusinessPartnerNotFoundException>(); | ||||
| 
 | ||||
|         } | ||||
| 
 | ||||
|         [Fact] | ||||
|         private async void TestGetCustomerById_Sucess() | ||||
|         { | ||||
|             var id = Guid.NewGuid(); | ||||
|             CancellationToken cancellationToken = default; | ||||
|             var customer = new Customer { CustomerId = id }; | ||||
|             _customerRepositoryMock.Setup(repo => repo.GetByIdAsync(id, cancellationToken)).ReturnsAsync(customer); | ||||
| 
 | ||||
|             var customerService = new CustomerService(_customerRepositoryMock.Object, _unitOfWorkMock.Object); | ||||
| 
 | ||||
|             var dto = await customerService.GetByIdAsync(id, cancellationToken); | ||||
| 
 | ||||
|             dto.Should().NotBeNull(); | ||||
|             dto.Id.Should().Be(id); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										3
									
								
								AB.Tests/Usings.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								AB.Tests/Usings.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,3 @@ | ||||
| global using Xunit; | ||||
| global using FluentAssertions; | ||||
| global using Moq; | ||||
							
								
								
									
										24
									
								
								AB.WEB/AB.WEB.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								AB.WEB/AB.WEB.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,24 @@ | ||||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||||
| 
 | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net6.0</TargetFramework> | ||||
|     <Nullable>enable</Nullable> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|     <RootNamespace>AB_API</RootNamespace> | ||||
|   </PropertyGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5"> | ||||
|       <PrivateAssets>all</PrivateAssets> | ||||
|       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||||
|     </PackageReference> | ||||
|     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
|   <ItemGroup> | ||||
|     <ProjectReference Include="..\AB.API\AB.API.csproj" /> | ||||
|     <ProjectReference Include="..\AB.Persistence\AB.Persistence.csproj" /> | ||||
|     <ProjectReference Include="..\AB.Services\AB.Services.csproj" /> | ||||
|   </ItemGroup> | ||||
| 
 | ||||
| </Project> | ||||
							
								
								
									
										38
									
								
								AB.WEB/Middleware/ExceptionHandlingMiddleware.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								AB.WEB/Middleware/ExceptionHandlingMiddleware.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,38 @@ | ||||
| using AB.Domain.Exceptions; | ||||
| using System.Text.Json; | ||||
| 
 | ||||
| namespace AB_API.Middleware | ||||
| { | ||||
|     public class ExceptionHandlingMiddleware : IMiddleware | ||||
|     { | ||||
|         public async Task InvokeAsync(HttpContext context, RequestDelegate next) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 await next(context); | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|             { | ||||
|                 await HandleExceptionAsync(context, ex); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         private async Task HandleExceptionAsync(HttpContext httpContext, Exception ex) | ||||
|         { | ||||
|             httpContext.Response.ContentType = "application/json"; | ||||
| 
 | ||||
|             httpContext.Response.StatusCode = ex switch | ||||
|             { | ||||
|                 NotFoundException => StatusCodes.Status404NotFound, | ||||
|                 _ => StatusCodes.Status400BadRequest | ||||
|             }; | ||||
| 
 | ||||
|             var response = new | ||||
|             { | ||||
|                 error = ex.Message | ||||
|             }; | ||||
| 
 | ||||
|             await httpContext.Response.WriteAsJsonAsync(response); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										66
									
								
								AB.WEB/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								AB.WEB/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,66 @@ | ||||
| using AB.Domain.Repositories; | ||||
| using AB.Persistence; | ||||
| using AB.Persistence.Repos; | ||||
| using AB.Services; | ||||
| using AB.Services.Abstractions; | ||||
| using AB_API.Middleware; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.OpenApi.Models; | ||||
| using System.Reflection; | ||||
| using System.Text.Json.Serialization; | ||||
| 
 | ||||
| var builder = WebApplication.CreateBuilder(args); | ||||
| 
 | ||||
| // Add services to the container. | ||||
| 
 | ||||
| builder.Services.AddControllers().AddApplicationPart(typeof(AB.API.AssemblyReference).Assembly) | ||||
|     .AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter())); | ||||
| 
 | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(c => | ||||
| { | ||||
|     c.SwaggerDoc("v1", new OpenApiInfo | ||||
|     { | ||||
|         Title = "AB-API", | ||||
|         Version = "v1", | ||||
|         Description = "An Api for the AB-Application" | ||||
|     }); | ||||
| 
 | ||||
|     var xmlFilename = $"{typeof(AB.API.AssemblyReference).Assembly.GetName().Name}.xml"; | ||||
|     c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); | ||||
| }); | ||||
| 
 | ||||
| builder.Services.AddScoped<ICustomerService, CustomerService>(); | ||||
| builder.Services.AddScoped<ICustomerRepository, CustomerRepository>(); | ||||
| 
 | ||||
| builder.Services.AddScoped<ISupplierService, SupplierService>(); | ||||
| builder.Services.AddScoped<ISupplierRepository, SupplierRepository>(); | ||||
| 
 | ||||
| builder.Services.AddScoped<IUnitOfWork, UnitOfWork>(); | ||||
| 
 | ||||
| builder.Services.AddDbContextPool<RepoDbContext>(builder => | ||||
| { | ||||
|     builder.UseInMemoryDatabase("test"); | ||||
| }); | ||||
| 
 | ||||
| builder.Services.AddTransient<ExceptionHandlingMiddleware>(); | ||||
| 
 | ||||
| var app = builder.Build(); | ||||
| 
 | ||||
| // Configure the HTTP request pipeline. | ||||
| if (app.Environment.IsDevelopment()) | ||||
| { | ||||
|     app.UseSwagger(); | ||||
|     app.UseSwaggerUI(); | ||||
| } | ||||
| 
 | ||||
| app.UseMiddleware<ExceptionHandlingMiddleware>(); | ||||
| 
 | ||||
| app.UseHttpsRedirection(); | ||||
| 
 | ||||
| app.UseAuthorization(); | ||||
| 
 | ||||
| app.MapControllers(); | ||||
| 
 | ||||
| app.Run(); | ||||
							
								
								
									
										31
									
								
								AB.WEB/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								AB.WEB/Properties/launchSettings.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,31 @@ | ||||
| { | ||||
|   "$schema": "https://json.schemastore.org/launchsettings.json", | ||||
|   "iisSettings": { | ||||
|     "windowsAuthentication": false, | ||||
|     "anonymousAuthentication": true, | ||||
|     "iisExpress": { | ||||
|       "applicationUrl": "http://localhost:25034", | ||||
|       "sslPort": 44354 | ||||
|     } | ||||
|   }, | ||||
|   "profiles": { | ||||
|     "AB_API": { | ||||
|       "commandName": "Project", | ||||
|       "dotnetRunMessages": true, | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "applicationUrl": "https://localhost:7196;http://localhost:5286", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Development" | ||||
|       } | ||||
|     }, | ||||
|     "IIS Express": { | ||||
|       "commandName": "IISExpress", | ||||
|       "launchBrowser": true, | ||||
|       "launchUrl": "swagger", | ||||
|       "environmentVariables": { | ||||
|         "ASPNETCORE_ENVIRONMENT": "Development" | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										8
									
								
								AB.WEB/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								AB.WEB/appsettings.Development.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										9
									
								
								AB.WEB/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								AB.WEB/appsettings.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,9 @@ | ||||
| { | ||||
|   "Logging": { | ||||
|     "LogLevel": { | ||||
|       "Default": "Information", | ||||
|       "Microsoft.AspNetCore": "Warning" | ||||
|     } | ||||
|   }, | ||||
|   "AllowedHosts": "*" | ||||
| } | ||||
							
								
								
									
										19
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								README.md
									
									
									
									
									
								
							| @ -1,2 +1,21 @@ | ||||
| # Mini-AB | ||||
| 
 | ||||
| Eine Anwendung zum erstellen von Belegen und zum verwalten von Kunden und Lieferanten Daten sowie von Produkten. | ||||
| 
 | ||||
| Hier ein Link zur der Collection unserer Rest-API: | ||||
| https://elements.getpostman.com/redirect?entityId=19696438-2f494a5b-ad52-4fb3-a864-ba739b638ca7&entityType=collection | ||||
| 
 | ||||
| Visualisierung der Rest-API erfolgt via Swagger: Swagger ist unter dem Endpunkt /swagger/index.html zu erreichen. | ||||
| 
 | ||||
| Geplante Endpunkte: | ||||
| 
 | ||||
| PUT suppliers/{id} | ||||
| 
 | ||||
| POST products/ | ||||
| GET products/ | ||||
| GET products/{id} | ||||
| PUT products/{id} | ||||
| DELETE products/{id} | ||||
| 
 | ||||
| POST invoices/ | ||||
| GET invoices/{id} | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user