Skip to content

Commit aa7d535

Browse files
committed
Initial commit
1 parent f1ae1a0 commit aa7d535

36 files changed

+1093
-1
lines changed

Diff for: .gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

Diff for: AccountOwnerServer.sln

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Diff for: AccountOwnerServer/AccountOwnerServer.csproj

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Folder Include="wwwroot\" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
13+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\Contracts\Contracts.csproj" />
22+
<ProjectReference Include="..\Entities\Entities.csproj" />
23+
<ProjectReference Include="..\LoggerService\LoggerService.csproj" />
24+
<ProjectReference Include="..\Repository\Repository.csproj" />
25+
</ItemGroup>
26+
27+
</Project>

Diff for: AccountOwnerServer/Controllers/OwnerController.cs

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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+
}

Diff for: AccountOwnerServer/Controllers/ValuesController.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

Diff for: AccountOwnerServer/Extensions/ServiceExtensions.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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<IISOptions>(options =>
33+
{
34+
35+
});
36+
}
37+
38+
public static void ConfigureLoggerService(this IServiceCollection services)
39+
{
40+
services.AddSingleton<ILoggerManager, LoggerManager>();
41+
}
42+
43+
public static void ConfigureMySqlContext(this IServiceCollection services, IConfiguration config)
44+
{
45+
var connectionString = config["mysqlconnection:connectionString"];
46+
services.AddDbContext<RepositoryContext>(o => o.UseMySql(connectionString));
47+
}
48+
49+
public static void ConfigureRepositoryWrapper(this IServiceCollection services)
50+
{
51+
services.AddScoped<IRepositoryWrapper, RepositoryWrapper>();
52+
}
53+
}
54+
}

Diff for: AccountOwnerServer/Program.cs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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<Startup>()
23+
.Build();
24+
}
25+
}

0 commit comments

Comments
 (0)