├── .gitignore ├── .travis.yml ├── AccountOwnerServer.sln ├── AccountOwnerServer ├── AccountOwnerServer.csproj ├── Controllers │ ├── OwnerController.cs │ └── ValuesController.cs ├── Extensions │ └── ServiceExtensions.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json └── nlog.config ├── Contracts ├── Contracts.csproj ├── IAccountRepository.cs ├── ILoggerManager.cs ├── IOwnerRepository.cs ├── IRepositoryBase.cs └── IRepositoryWrapper.cs ├── Entities ├── Entities.csproj ├── Enumerations │ └── AccountType.cs ├── ExtendedModels │ └── OwnerExtended.cs ├── Extensions │ ├── IEntityExtensions.cs │ └── OwnerExtensions.cs ├── IEntity.cs ├── Models │ ├── Account.cs │ └── Owner.cs └── RepositoryContext.cs ├── LoggerService ├── LoggerManager.cs └── LoggerService.csproj ├── README.md ├── Repository ├── AccountRepository.cs ├── OwnerRepository.cs ├── Repository.csproj ├── RepositoryBase.cs └── RepositoryWrapper.cs └── _MySQL_Init_Script └── init.sql /.gitignore: -------------------------------------------------------------------------------- 1 | /AccountOwnerServer/obj 2 | /AccountOwnerServer/bin 3 | /Contracts/obj 4 | /Contracts/bin 5 | /Entities/obj 6 | /Entities/bin 7 | /LoggerService/obj 8 | /LoggerService/bin 9 | /Repository/obj 10 | /Repository/bin 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | mono: none 3 | dotnet: 2.0 4 | script: 5 | - dotnet restore 6 | - dotnet build 7 | -------------------------------------------------------------------------------- /AccountOwnerServer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26730.3 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccountOwnerServer", "AccountOwnerServer\AccountOwnerServer.csproj", "{73FB08B8-4033-4116-B3AC-EC8253B024D4}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{52725034-B791-4DF1-A227-02EDB5BF78E0}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoggerService", "LoggerService\LoggerService.csproj", "{A190AF01-84DC-40A8-BEF3-C015825C8B30}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entities.csproj", "{8CD97B3F-C616-469C-80A2-A1B366611487}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{CC0B1C81-CB8A-412C-BD48-BCBC3F1A1CD0}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {73FB08B8-4033-4116-B3AC-EC8253B024D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {73FB08B8-4033-4116-B3AC-EC8253B024D4}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {73FB08B8-4033-4116-B3AC-EC8253B024D4}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {73FB08B8-4033-4116-B3AC-EC8253B024D4}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {52725034-B791-4DF1-A227-02EDB5BF78E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {52725034-B791-4DF1-A227-02EDB5BF78E0}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {52725034-B791-4DF1-A227-02EDB5BF78E0}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {52725034-B791-4DF1-A227-02EDB5BF78E0}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {A190AF01-84DC-40A8-BEF3-C015825C8B30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {A190AF01-84DC-40A8-BEF3-C015825C8B30}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {A190AF01-84DC-40A8-BEF3-C015825C8B30}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {A190AF01-84DC-40A8-BEF3-C015825C8B30}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {8CD97B3F-C616-469C-80A2-A1B366611487}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {8CD97B3F-C616-469C-80A2-A1B366611487}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {8CD97B3F-C616-469C-80A2-A1B366611487}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {8CD97B3F-C616-469C-80A2-A1B366611487}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {CC0B1C81-CB8A-412C-BD48-BCBC3F1A1CD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {CC0B1C81-CB8A-412C-BD48-BCBC3F1A1CD0}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {CC0B1C81-CB8A-412C-BD48-BCBC3F1A1CD0}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {CC0B1C81-CB8A-412C-BD48-BCBC3F1A1CD0}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {86DE07EE-BE1C-4AAB-ADAA-224170CF42B0} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /AccountOwnerServer/AccountOwnerServer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AccountOwnerServer/Controllers/OwnerController.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities.Extensions; 3 | using Entities.Models; 4 | using Microsoft.AspNetCore.Mvc; 5 | using System; 6 | 7 | namespace AccountOwnerServer.Controllers 8 | { 9 | [Route("api/owner")] 10 | public class OwnerController : Controller 11 | { 12 | private ILoggerManager _logger; 13 | private IRepositoryWrapper _repository; 14 | 15 | public OwnerController(ILoggerManager logger, IRepositoryWrapper repository) 16 | { 17 | _logger = logger; 18 | _repository = repository; 19 | } 20 | 21 | [HttpGet] 22 | public IActionResult GetAllOwners() 23 | { 24 | try 25 | { 26 | var owners = _repository.Owner.GetAllOwners(); 27 | 28 | _logger.LogInfo($"Returned all owners from database."); 29 | 30 | return Ok(owners); 31 | } 32 | catch (Exception ex) 33 | { 34 | _logger.LogError($"Something went wrong inside GetAllOwners action: {ex.Message}"); 35 | return StatusCode(500, "Internal server error"); 36 | } 37 | } 38 | 39 | [HttpGet("{id}", Name = "OwnerById")] 40 | public IActionResult GetOwnerById(Guid id) 41 | { 42 | try 43 | { 44 | var owner = _repository.Owner.GetOwnerById(id); 45 | 46 | if (owner.IsEmptyObject()) 47 | { 48 | _logger.LogError($"Owner with id: {id}, hasn't been found in db."); 49 | return NotFound(); 50 | } 51 | else 52 | { 53 | _logger.LogInfo($"Returned owner with id: {id}"); 54 | return Ok(owner); 55 | } 56 | } 57 | catch (Exception ex) 58 | { 59 | _logger.LogError($"Something went wrong inside GetOwnerById action: {ex.Message}"); 60 | return StatusCode(500, "Internal server error"); 61 | } 62 | } 63 | 64 | [HttpGet("{id}/account")] 65 | public IActionResult GetOwnerWithDetails(Guid id) 66 | { 67 | try 68 | { 69 | var owner = _repository.Owner.GetOwnerWithDetails(id); 70 | 71 | if (owner.IsEmptyObject()) 72 | { 73 | _logger.LogError($"Owner with id: {id}, hasn't been found in db."); 74 | return NotFound(); 75 | } 76 | else 77 | { 78 | _logger.LogInfo($"Returned owner with details for id: {id}"); 79 | return Ok(owner); 80 | } 81 | } 82 | catch (Exception ex) 83 | { 84 | _logger.LogError($"Something went wrong inside GetOwnerWithDetails action: {ex.Message}"); 85 | return StatusCode(500, "Internal server error"); 86 | } 87 | } 88 | 89 | [HttpPost] 90 | public IActionResult CreateOwner([FromBody]Owner owner) 91 | { 92 | try 93 | { 94 | if (owner.IsObjectNull()) 95 | { 96 | _logger.LogError("Owner object sent from client is null."); 97 | return BadRequest("Owner object is null"); 98 | } 99 | 100 | if (!ModelState.IsValid) 101 | { 102 | _logger.LogError("Invalid owner object sent from client."); 103 | return BadRequest("Invalid model object"); 104 | } 105 | 106 | _repository.Owner.CreateOwner(owner); 107 | 108 | return CreatedAtRoute("OwnerById", new { id = owner.Id }, owner); 109 | } 110 | catch (Exception ex) 111 | { 112 | _logger.LogError($"Something went wrong inside CreateOwner action: {ex.Message}"); 113 | return StatusCode(500, "Internal server error"); 114 | } 115 | } 116 | 117 | [HttpPut("{id}")] 118 | public IActionResult UpdateOwner(Guid id, [FromBody]Owner owner) 119 | { 120 | try 121 | { 122 | if (owner.IsObjectNull()) 123 | { 124 | _logger.LogError("Owner object sent from client is null."); 125 | return BadRequest("Owner object is null"); 126 | } 127 | 128 | if (!ModelState.IsValid) 129 | { 130 | _logger.LogError("Invalid owner object sent from client."); 131 | return BadRequest("Invalid model object"); 132 | } 133 | 134 | var dbOwner = _repository.Owner.GetOwnerById(id); 135 | if (dbOwner.IsEmptyObject()) 136 | { 137 | _logger.LogError($"Owner with id: {id}, hasn't been found in db."); 138 | return NotFound(); 139 | } 140 | 141 | _repository.Owner.UpdateOwner(dbOwner, owner); 142 | 143 | return NoContent(); 144 | } 145 | catch (Exception ex) 146 | { 147 | _logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}"); 148 | return StatusCode(500, "Internal server error"); 149 | } 150 | } 151 | 152 | [HttpDelete("{id}")] 153 | public IActionResult DeleteOwner(Guid id) 154 | { 155 | try 156 | { 157 | var owner = _repository.Owner.GetOwnerById(id); 158 | if (owner.IsEmptyObject()) 159 | { 160 | _logger.LogError($"Owner with id: {id}, hasn't been found in db."); 161 | return NotFound(); 162 | } 163 | 164 | _repository.Owner.DeleteOwner(owner); 165 | 166 | return NoContent(); 167 | } 168 | catch (Exception ex) 169 | { 170 | _logger.LogError($"Something went wrong inside DeleteOwner action: {ex.Message}"); 171 | return StatusCode(500, "Internal server error"); 172 | } 173 | } 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /AccountOwnerServer/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Contracts; 7 | using Entities; 8 | using Entities.Enumerations; 9 | using Entities.Models; 10 | 11 | namespace AccountOwnerServer.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | public class ValuesController : Controller 15 | { 16 | private ILoggerManager _logger; 17 | private IRepositoryWrapper _repoWrapper; 18 | 19 | public ValuesController(ILoggerManager logger, IRepositoryWrapper repoWrapper) 20 | { 21 | _logger = logger; 22 | _repoWrapper = repoWrapper; 23 | } 24 | // GET api/values 25 | [HttpGet] 26 | public IActionResult Get() 27 | { 28 | //var domesticAccounts = _repoWrapper.Account.FindByCondition(x => x.AccountType.Equals("Domestic")); 29 | var owners = _repoWrapper.Owner.GetAllOwners(); 30 | 31 | _logger.LogInfo("Here is info message from our values controller."); 32 | _logger.LogDebug("Here is debug message from our values controller."); 33 | _logger.LogWarn("Here is warn message from our values controller."); 34 | _logger.LogError("Here is error message from our values controller."); 35 | 36 | return Ok(owners); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /AccountOwnerServer/Extensions/ServiceExtensions.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities; 3 | using LoggerService; 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.EntityFrameworkCore; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Repository; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Threading.Tasks; 13 | 14 | namespace AccountOwnerServer.Extensions 15 | { 16 | public static class ServiceExtensions 17 | { 18 | public static void ConfigureCors(this IServiceCollection services) 19 | { 20 | services.AddCors(options => 21 | { 22 | options.AddPolicy("CorsPolicy", 23 | builder => builder.AllowAnyOrigin() 24 | .AllowAnyMethod() 25 | .AllowAnyHeader() 26 | .AllowCredentials()); 27 | }); 28 | } 29 | 30 | public static void ConfigureIISIntegration(this IServiceCollection services) 31 | { 32 | services.Configure(options => 33 | { 34 | 35 | }); 36 | } 37 | 38 | public static void ConfigureLoggerService(this IServiceCollection services) 39 | { 40 | services.AddSingleton(); 41 | } 42 | 43 | public static void ConfigureMySqlContext(this IServiceCollection services, IConfiguration config) 44 | { 45 | var connectionString = config["mysqlconnection:connectionString"]; 46 | services.AddDbContext(o => o.UseMySql(connectionString)); 47 | } 48 | 49 | public static void ConfigureRepositoryWrapper(this IServiceCollection services) 50 | { 51 | services.AddScoped(); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /AccountOwnerServer/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 AccountOwnerServer 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 | -------------------------------------------------------------------------------- /AccountOwnerServer/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:5000/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": false, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "AccountOwnerServer": { 19 | "commandName": "Project", 20 | "launchBrowser": false, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000/" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /AccountOwnerServer/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | using Microsoft.Extensions.Options; 11 | using AccountOwnerServer.Extensions; 12 | using Microsoft.AspNetCore.HttpOverrides; 13 | using System.IO; 14 | using NLog.Extensions.Logging; 15 | using Contracts; 16 | 17 | namespace AccountOwnerServer 18 | { 19 | public class Startup 20 | { 21 | public Startup(IConfiguration configuration, ILoggerFactory loggerFactory) 22 | { 23 | loggerFactory.ConfigureNLog(String.Concat(Directory.GetCurrentDirectory(), "/nlog.config")); 24 | Configuration = configuration; 25 | } 26 | 27 | public IConfiguration Configuration { get; } 28 | 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | services.ConfigureCors(); 32 | 33 | services.ConfigureIISIntegration(); 34 | 35 | services.ConfigureLoggerService(); 36 | 37 | services.ConfigureMySqlContext(Configuration); 38 | 39 | services.ConfigureRepositoryWrapper(); 40 | 41 | services.AddMvc(); 42 | } 43 | 44 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 45 | { 46 | if (env.IsDevelopment()) 47 | { 48 | app.UseDeveloperExceptionPage(); 49 | } 50 | 51 | app.UseCors("CorsPolicy"); 52 | 53 | app.UseForwardedHeaders(new ForwardedHeadersOptions 54 | { 55 | ForwardedHeaders = ForwardedHeaders.All 56 | }); 57 | 58 | app.Use(async (context, next) => 59 | { 60 | await next(); 61 | 62 | if (context.Response.StatusCode == 404 63 | && !Path.HasExtension(context.Request.Path.Value)) 64 | { 65 | context.Request.Path = "/index.html"; 66 | await next(); 67 | } 68 | }); 69 | 70 | app.UseStaticFiles(); 71 | 72 | app.UseMvc(); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /AccountOwnerServer/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /AccountOwnerServer/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | }, 15 | "mysqlconnection": { 16 | "connectionString": "server=localhost;userid=dbuser;password=pass;database=accountowner;" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /AccountOwnerServer/nlog.config: -------------------------------------------------------------------------------- 1 |  2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Contracts/Contracts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Contracts/IAccountRepository.cs: -------------------------------------------------------------------------------- 1 | using Entities.Models; 2 | 3 | namespace Contracts 4 | { 5 | public interface IAccountRepository 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Contracts/ILoggerManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Contracts 6 | { 7 | public interface ILoggerManager 8 | { 9 | void LogInfo(string message); 10 | void LogWarn(string message); 11 | void LogDebug(string message); 12 | void LogError(string message); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Contracts/IOwnerRepository.cs: -------------------------------------------------------------------------------- 1 | using Entities.ExtendedModels; 2 | using Entities.Models; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Contracts 7 | { 8 | public interface IOwnerRepository 9 | { 10 | IEnumerable GetAllOwners(); 11 | Owner GetOwnerById(Guid ownerId); 12 | OwnerExtended GetOwnerWithDetails(Guid ownerId); 13 | void CreateOwner(Owner owner); 14 | void UpdateOwner(Owner dbOwner, Owner owner); 15 | void DeleteOwner(Owner owner); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Contracts/IRepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Text; 5 | 6 | namespace Contracts 7 | { 8 | public interface IRepositoryBase 9 | { 10 | IEnumerable FindAll(); 11 | IEnumerable FindByCondition(Expression> expression); 12 | void Create(T entity); 13 | void Update(T entity); 14 | void Delete(T entity); 15 | void Save(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Contracts/IRepositoryWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Contracts 6 | { 7 | public interface IRepositoryWrapper 8 | { 9 | IOwnerRepository Owner { get; } 10 | IAccountRepository Account { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Entities/Entities.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Entities/Enumerations/AccountType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.Enumerations 6 | { 7 | public enum AccountType 8 | { 9 | Domestic, 10 | Savings, 11 | Foreign 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Entities/ExtendedModels/OwnerExtended.cs: -------------------------------------------------------------------------------- 1 | using Entities.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.ExtendedModels 7 | { 8 | public class OwnerExtended: IEntity 9 | { 10 | public Guid Id { get; set; } 11 | public string Name { get; set; } 12 | public DateTime DateOfBirth { get; set; } 13 | public string Address { get; set; } 14 | 15 | public IEnumerable Accounts { get; set; } 16 | 17 | public OwnerExtended() 18 | { 19 | } 20 | 21 | public OwnerExtended(Owner owner) 22 | { 23 | Id = owner.Id; 24 | Name = owner.Name; 25 | DateOfBirth = owner.DateOfBirth; 26 | Address = owner.Address; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Entities/Extensions/IEntityExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities.Extensions 6 | { 7 | public static class IEntityExtensions 8 | { 9 | public static bool IsObjectNull(this IEntity entity) 10 | { 11 | return entity == null; 12 | } 13 | 14 | public static bool IsEmptyObject(this IEntity entity) 15 | { 16 | return entity.Id.Equals(Guid.Empty); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Entities/Extensions/OwnerExtensions.cs: -------------------------------------------------------------------------------- 1 | using Entities.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace Entities.Extensions 7 | { 8 | public static class OwnerExtensions 9 | { 10 | public static void Map(this Owner dbOwner, Owner owner) 11 | { 12 | dbOwner.Name = owner.Name; 13 | dbOwner.Address = owner.Address; 14 | dbOwner.DateOfBirth = owner.DateOfBirth; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Entities/IEntity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Entities 6 | { 7 | public interface IEntity 8 | { 9 | Guid Id { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Entities/Models/Account.cs: -------------------------------------------------------------------------------- 1 | using Entities.Enumerations; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel.DataAnnotations; 5 | using System.ComponentModel.DataAnnotations.Schema; 6 | using System.Text; 7 | 8 | namespace Entities.Models 9 | { 10 | [Table("account")] 11 | public class Account : IEntity 12 | { 13 | [Key] 14 | [Column("AccountId")] 15 | public Guid Id { get; set; } 16 | 17 | [Required(ErrorMessage = "Date created is required")] 18 | public DateTime DateCreated { get; set; } 19 | 20 | [Required(ErrorMessage = "Account type is required")] 21 | public string AccountType { get; set; } 22 | 23 | [Required(ErrorMessage = "Owner Id is required")] 24 | public Guid OwnerId { get; set; } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Entities/Models/Owner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.ComponentModel.DataAnnotations.Schema; 5 | using System.Text; 6 | 7 | namespace Entities.Models 8 | { 9 | [Table("owner")] 10 | public class Owner: IEntity 11 | { 12 | [Key] 13 | [Column("OwnerId")] 14 | public Guid Id { get; set; } 15 | 16 | [Required(ErrorMessage = "Name is required")] 17 | [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")] 18 | public string Name { get; set; } 19 | 20 | [Required(ErrorMessage = "Date of birth is required")] 21 | public DateTime DateOfBirth { get; set; } 22 | 23 | [Required(ErrorMessage = "Address is required")] 24 | [StringLength(100, ErrorMessage = "Address can not be loner then 100 characters")] 25 | public string Address { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Entities/RepositoryContext.cs: -------------------------------------------------------------------------------- 1 | using Entities.Models; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace Entities 5 | { 6 | public class RepositoryContext: DbContext 7 | { 8 | public RepositoryContext(DbContextOptions options) 9 | :base(options) 10 | { 11 | } 12 | 13 | public DbSet Owners { get; set; } 14 | public DbSet Accounts { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LoggerService/LoggerManager.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using NLog; 3 | using System; 4 | 5 | namespace LoggerService 6 | { 7 | public class LoggerManager : ILoggerManager 8 | { 9 | private static ILogger logger = LogManager.GetCurrentClassLogger(); 10 | 11 | public LoggerManager() 12 | { 13 | } 14 | 15 | public void LogDebug(string message) 16 | { 17 | logger.Debug(message); 18 | } 19 | 20 | public void LogError(string message) 21 | { 22 | logger.Error(message); 23 | } 24 | 25 | public void LogInfo(string message) 26 | { 27 | logger.Info(message); 28 | } 29 | 30 | public void LogWarn(string message) 31 | { 32 | logger.Warn(message); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LoggerService/LoggerService.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker Series 2 | https://code-maze.com/docker-series/ 3 | 4 | ## Part 1 of the Docker Series on CodeMaze blog 5 | https://code-maze.com/how-to-prepare-aspnetcore-app-dockerization/ 6 | -------------------------------------------------------------------------------- /Repository/AccountRepository.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities; 3 | using Entities.Models; 4 | 5 | namespace Repository 6 | { 7 | public class AccountRepository: RepositoryBase, IAccountRepository 8 | { 9 | public AccountRepository(RepositoryContext repositoryContext) 10 | :base(repositoryContext) 11 | { 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Repository/OwnerRepository.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities; 3 | using Entities.Models; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System; 7 | using Entities.ExtendedModels; 8 | using Entities.Extensions; 9 | 10 | namespace Repository 11 | { 12 | public class OwnerRepository: RepositoryBase, IOwnerRepository 13 | { 14 | public OwnerRepository(RepositoryContext repositoryContext) 15 | :base(repositoryContext) 16 | { 17 | } 18 | 19 | public IEnumerable GetAllOwners() 20 | { 21 | return FindAll() 22 | .OrderBy(ow => ow.Name); 23 | } 24 | 25 | public Owner GetOwnerById(Guid ownerId) 26 | { 27 | return FindByCondition(owner => owner.Id.Equals(ownerId)) 28 | .DefaultIfEmpty(new Owner()) 29 | .FirstOrDefault(); 30 | } 31 | 32 | public OwnerExtended GetOwnerWithDetails(Guid ownerId) 33 | { 34 | return new OwnerExtended(GetOwnerById(ownerId)) 35 | { 36 | Accounts = RepositoryContext.Accounts 37 | .Where(a => a.OwnerId == ownerId) 38 | }; 39 | } 40 | 41 | public void CreateOwner(Owner owner) 42 | { 43 | owner.Id = Guid.NewGuid(); 44 | Create(owner); 45 | Save(); 46 | } 47 | 48 | public void UpdateOwner(Owner dbOwner, Owner owner) 49 | { 50 | dbOwner.Map(owner); 51 | Update(dbOwner); 52 | Save(); 53 | } 54 | 55 | public void DeleteOwner(Owner owner) 56 | { 57 | Delete(owner); 58 | Save(); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Repository/Repository.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Repository/RepositoryBase.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Linq.Expressions; 7 | 8 | namespace Repository 9 | { 10 | public abstract class RepositoryBase : IRepositoryBase where T : class 11 | { 12 | protected RepositoryContext RepositoryContext { get; set; } 13 | 14 | public RepositoryBase(RepositoryContext repositoryContext) 15 | { 16 | this.RepositoryContext = repositoryContext; 17 | } 18 | 19 | public IEnumerable FindAll() 20 | { 21 | return this.RepositoryContext.Set(); 22 | } 23 | 24 | public IEnumerable FindByCondition(Expression> expression) 25 | { 26 | return this.RepositoryContext.Set().Where(expression); 27 | } 28 | 29 | public void Create(T entity) 30 | { 31 | this.RepositoryContext.Set().Add(entity); 32 | } 33 | 34 | public void Update(T entity) 35 | { 36 | this.RepositoryContext.Set().Update(entity); 37 | } 38 | 39 | public void Delete(T entity) 40 | { 41 | this.RepositoryContext.Set().Remove(entity); 42 | } 43 | 44 | public void Save() 45 | { 46 | this.RepositoryContext.SaveChanges(); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Repository/RepositoryWrapper.cs: -------------------------------------------------------------------------------- 1 | using Contracts; 2 | using Entities; 3 | 4 | namespace Repository 5 | { 6 | public class RepositoryWrapper : IRepositoryWrapper 7 | { 8 | private RepositoryContext _repoContext; 9 | private IOwnerRepository _owner; 10 | private IAccountRepository _account; 11 | 12 | public IOwnerRepository Owner 13 | { 14 | get 15 | { 16 | if (_owner == null) 17 | { 18 | _owner = new OwnerRepository(_repoContext); 19 | } 20 | 21 | return _owner; 22 | } 23 | } 24 | 25 | public IAccountRepository Account 26 | { 27 | get 28 | { 29 | if (_account == null) 30 | { 31 | _account = new AccountRepository(_repoContext); 32 | } 33 | 34 | return _account; 35 | } 36 | } 37 | 38 | public RepositoryWrapper(RepositoryContext repositoryContext) 39 | { 40 | _repoContext = repositoryContext; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /_MySQL_Init_Script/init.sql: -------------------------------------------------------------------------------- 1 | -- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) 2 | -- 3 | -- Host: localhost Database: accountowner 4 | -- ------------------------------------------------------ 5 | -- Server version 5.7.17-log 6 | 7 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 8 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 9 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 10 | /*!40101 SET NAMES utf8 */; 11 | /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; 12 | /*!40103 SET TIME_ZONE='+00:00' */; 13 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 14 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 15 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 16 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 17 | 18 | -- 19 | -- Table structure for table `account` 20 | -- 21 | 22 | DROP TABLE IF EXISTS `account`; 23 | /*!40101 SET @saved_cs_client = @@character_set_client */; 24 | /*!40101 SET character_set_client = utf8 */; 25 | CREATE TABLE `account` ( 26 | `AccountId` char(36) NOT NULL, 27 | `DateCreated` date NOT NULL, 28 | `AccountType` varchar(45) NOT NULL, 29 | `OwnerId` char(36) NOT NULL, 30 | PRIMARY KEY (`AccountId`), 31 | KEY `fk_Account_Owner_idx` (`OwnerId`), 32 | CONSTRAINT `fk_Account_Owner` FOREIGN KEY (`OwnerId`) REFERENCES `owner` (`OwnerId`) ON UPDATE CASCADE 33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 34 | /*!40101 SET character_set_client = @saved_cs_client */; 35 | 36 | -- 37 | -- Dumping data for table `account` 38 | -- 39 | 40 | LOCK TABLES `account` WRITE; 41 | /*!40000 ALTER TABLE `account` DISABLE KEYS */; 42 | INSERT INTO `account` VALUES ('03e91478-5608-4132-a753-d494dafce00b','2003-12-15','Domestic','f98e4d74-0f68-4aac-89fd-047f1aaca6b6'),('356a5a9b-64bf-4de0-bc84-5395a1fdc9c4','1996-02-15','Domestic','261e1685-cf26-494c-b17c-3546e65f5620'),('371b93f2-f8c5-4a32-894a-fc672741aa5b','1999-05-04','Domestic','24fd81f8-d58a-4bcc-9f35-dc6cd5641906'),('670775db-ecc0-4b90-a9ab-37cd0d8e2801','1999-12-21','Savings','24fd81f8-d58a-4bcc-9f35-dc6cd5641906'),('a3fbad0b-7f48-4feb-8ac0-6d3bbc997bfc','2010-05-28','Domestic','a3c1880c-674c-4d18-8f91-5d3608a2c937'),('aa15f658-04bb-4f73-82af-82db49d0fbef','1999-05-12','Foreign','24fd81f8-d58a-4bcc-9f35-dc6cd5641906'),('c6066eb0-53ca-43e1-97aa-3c2169eec659','1996-02-16','Foreign','261e1685-cf26-494c-b17c-3546e65f5620'),('eccadf79-85fe-402f-893c-32d3f03ed9b1','2010-06-20','Foreign','a3c1880c-674c-4d18-8f91-5d3608a2c937'); 43 | /*!40000 ALTER TABLE `account` ENABLE KEYS */; 44 | UNLOCK TABLES; 45 | 46 | -- 47 | -- Table structure for table `owner` 48 | -- 49 | 50 | DROP TABLE IF EXISTS `owner`; 51 | /*!40101 SET @saved_cs_client = @@character_set_client */; 52 | /*!40101 SET character_set_client = utf8 */; 53 | CREATE TABLE `owner` ( 54 | `OwnerId` char(36) NOT NULL, 55 | `Name` varchar(60) NOT NULL, 56 | `DateOfBirth` date NOT NULL, 57 | `Address` varchar(100) NOT NULL, 58 | PRIMARY KEY (`OwnerId`) 59 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 60 | /*!40101 SET character_set_client = @saved_cs_client */; 61 | 62 | -- 63 | -- Dumping data for table `owner` 64 | -- 65 | 66 | LOCK TABLES `owner` WRITE; 67 | /*!40000 ALTER TABLE `owner` DISABLE KEYS */; 68 | INSERT INTO `owner` VALUES ('24fd81f8-d58a-4bcc-9f35-dc6cd5641906','John Keen','1980-12-05','61 Wellfield Road'),('261e1685-cf26-494c-b17c-3546e65f5620','Anna Bosh','1974-11-14','27 Colored Row'),('66774006-2371-4d5b-8518-2177bcf3f73e','Nick Somion','1998-12-15','North sunny address 102'),('a3c1880c-674c-4d18-8f91-5d3608a2c937','Sam Query','1990-04-22','91 Western Roads'),('f98e4d74-0f68-4aac-89fd-047f1aaca6b6','Martin Miller','1983-05-21','3 Edgar Buildings'); 69 | /*!40000 ALTER TABLE `owner` ENABLE KEYS */; 70 | UNLOCK TABLES; 71 | /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; 72 | 73 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 74 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 75 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 76 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 77 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 78 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 79 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 80 | 81 | -- Dump completed on 2017-12-24 15:53:17 82 | --------------------------------------------------------------------------------