Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# Angular Material Series
## https://code-maze.com/angular-material-series/
This repository contains the code that accompanies Angular Material on Code Maze
# Angular Material Series - Angular Material Form Validation, Input, Datepicker and Modal
## https://code-maze.com/angular-material-form-validation/
10 changes: 10 additions & 0 deletions _Server Code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/AccountOwnerServer/obj
/AccountOwnerServer/bin
/Contracts/obj
/Contracts/bin
/Entities/obj
/Entities/bin
/LoggerService/obj
/LoggerService/bin
/Repository/obj
/Repository/bin
Binary file not shown.
Binary file added _Server Code/.vs/AccountOwnerServer/v16/.suo
Binary file not shown.
49 changes: 49 additions & 0 deletions _Server Code/AccountOwnerServer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AccountOwnerServer", "AccountOwnerServer\AccountOwnerServer.csproj", "{D6116708-5D20-43C2-A796-9716AC8885F3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Contracts", "Contracts\Contracts.csproj", "{C6A5877A-BCBF-487C-B9EE-F678F921D3F2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LoggerService", "LoggerService\LoggerService.csproj", "{8F7CB858-3196-4D0C-A3DB-A850443CA462}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{CA018972-3651-4802-9930-69E855892B7A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Repository", "Repository\Repository.csproj", "{A1DEC662-9D40-45E3-A8DE-22AF6A1BE970}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D6116708-5D20-43C2-A796-9716AC8885F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6116708-5D20-43C2-A796-9716AC8885F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6116708-5D20-43C2-A796-9716AC8885F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6116708-5D20-43C2-A796-9716AC8885F3}.Release|Any CPU.Build.0 = Release|Any CPU
{C6A5877A-BCBF-487C-B9EE-F678F921D3F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6A5877A-BCBF-487C-B9EE-F678F921D3F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6A5877A-BCBF-487C-B9EE-F678F921D3F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6A5877A-BCBF-487C-B9EE-F678F921D3F2}.Release|Any CPU.Build.0 = Release|Any CPU
{8F7CB858-3196-4D0C-A3DB-A850443CA462}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8F7CB858-3196-4D0C-A3DB-A850443CA462}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F7CB858-3196-4D0C-A3DB-A850443CA462}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F7CB858-3196-4D0C-A3DB-A850443CA462}.Release|Any CPU.Build.0 = Release|Any CPU
{CA018972-3651-4802-9930-69E855892B7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CA018972-3651-4802-9930-69E855892B7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CA018972-3651-4802-9930-69E855892B7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CA018972-3651-4802-9930-69E855892B7A}.Release|Any CPU.Build.0 = Release|Any CPU
{A1DEC662-9D40-45E3-A8DE-22AF6A1BE970}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1DEC662-9D40-45E3-A8DE-22AF6A1BE970}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1DEC662-9D40-45E3-A8DE-22AF6A1BE970}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1DEC662-9D40-45E3-A8DE-22AF6A1BE970}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9552CCB3-10D6-4D12-8C27-FDD7440E23EB}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions _Server Code/AccountOwnerServer/AccountOwnerServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LoggerService\LoggerService.csproj" />
<ProjectReference Include="..\Repository\Repository.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions _Server Code/AccountOwnerServer/AccountOwnerServer.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup>
<ActiveDebugProfile>AccountOwnerServer</ActiveDebugProfile>
<Controller_SelectedScaffolderID>ApiControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Controller</Controller_SelectedScaffolderCategoryPath>
<WebStackScaffolding_ControllerDialogWidth>600</WebStackScaffolding_ControllerDialogWidth>
<WebStackScaffolding_IsLayoutPageSelected>True</WebStackScaffolding_IsLayoutPageSelected>
<WebStackScaffolding_IsPartialViewSelected>False</WebStackScaffolding_IsPartialViewSelected>
<WebStackScaffolding_IsReferencingScriptLibrariesSelected>True</WebStackScaffolding_IsReferencingScriptLibrariesSelected>
<WebStackScaffolding_LayoutPageFile />
<WebStackScaffolding_IsAsyncSelected>False</WebStackScaffolding_IsAsyncSelected>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>
186 changes: 186 additions & 0 deletions _Server Code/AccountOwnerServer/Controllers/OwnerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
using System;
using System.Linq;
using Contracts;
using Entities.Extensions;
using Entities.Models;
using Microsoft.AspNetCore.Mvc;

namespace AccountOwnerServer.Controllers
{
[Route("api/owner")]
[ApiController]
public class OwnerController : ControllerBase
{
private ILoggerManager _logger;
private IRepositoryWrapper _repository;

public OwnerController(ILoggerManager logger, IRepositoryWrapper repository)
{
_logger = logger;
_repository = repository;
}

[HttpGet]
public IActionResult GetAllOwners()
{
try
{
var owners = _repository.Owner.GetAllOwners();

_logger.LogInfo($"Returned all owners from database.");

return Ok(owners);
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside GetAllOwners action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}

[HttpGet("{id}", Name = "OwnerById")]
public IActionResult GetOwnerById(Guid id)
{
try
{
var owner = _repository.Owner.GetOwnerById(id);

if (owner.IsEmptyObject())
{
_logger.LogError($"Owner with id: {id}, hasn't been found in db.");
return NotFound();
}
else
{
_logger.LogInfo($"Returned owner with id: {id}");
return Ok(owner);
}
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside GetOwnerById action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}

[HttpGet("{id}/account")]
public IActionResult GetOwnerWithDetails(Guid id)
{
try
{
var owner = _repository.Owner.GetOwnerWithDetails(id);

if (owner.IsEmptyObject())
{
_logger.LogError($"Owner with id: {id}, hasn't been found in db.");
return NotFound();
}
else
{
_logger.LogInfo($"Returned owner with details for id: {id}");
return Ok(owner);
}
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside GetOwnerWithDetails action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}

[HttpPost]
public IActionResult CreateOwner([FromBody]Owner owner)
{
try
{
if (owner.IsObjectNull())
{
_logger.LogError("Owner object sent from client is null.");
return BadRequest("Owner object is null");
}

if (!ModelState.IsValid)
{
_logger.LogError("Invalid owner object sent from client.");
return BadRequest("Invalid model object");
}

_repository.Owner.CreateOwner(owner);
_repository.Save();

return CreatedAtRoute("OwnerById", new { id = owner.Id }, owner);
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside CreateOwner action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}

[HttpPut("{id}")]
public IActionResult UpdateOwner(Guid id, [FromBody]Owner owner)
{
try
{
if (owner.IsObjectNull())
{
_logger.LogError("Owner object sent from client is null.");
return BadRequest("Owner object is null");
}

if (!ModelState.IsValid)
{
_logger.LogError("Invalid owner object sent from client.");
return BadRequest("Invalid model object");
}

var dbOwner = _repository.Owner.GetOwnerById(id);
if (dbOwner.IsEmptyObject())
{
_logger.LogError($"Owner with id: {id}, hasn't been found in db.");
return NotFound();
}

_repository.Owner.UpdateOwner(dbOwner, owner);
_repository.Save();

return NoContent();
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside UpdateOwner action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}

[HttpDelete("{id}")]
public IActionResult DeleteOwner(Guid id)
{
try
{
var owner = _repository.Owner.GetOwnerById(id);
if (owner.IsEmptyObject())
{
_logger.LogError($"Owner with id: {id}, hasn't been found in db.");
return NotFound();
}

if (_repository.Account.AccountsByOwner(id).Any())
{
_logger.LogError($"Cannot delete owner with id: {id}. It has related accounts. Delete those accounts first");
return BadRequest("Cannot delete owner. It has related accounts. Delete those accounts first");
}

_repository.Owner.DeleteOwner(owner);
_repository.Save();

return NoContent();
}
catch (Exception ex)
{
_logger.LogError($"Something went wrong inside DeleteOwner action: {ex.Message}");
return StatusCode(500, "Internal server error");
}
}
}
}
54 changes: 54 additions & 0 deletions _Server Code/AccountOwnerServer/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contracts;
using Microsoft.AspNetCore.Mvc;

namespace AccountOwnerServer.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
private IRepositoryWrapper _repoWrapper;
public ValuesController(IRepositoryWrapper repoWrapper)
{
_repoWrapper = repoWrapper;
}
// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
var domesticAccounts = _repoWrapper.Account.FindByCondition(x => x.AccountType.Equals("Domestic"));
var owners = _repoWrapper.Owner.FindAll();

return new string[] { "value1", "value2" };
}

// GET api/values/5
[HttpGet("{id}")]
public ActionResult<string> Get(int id)
{
return "value";
}

// POST api/values
[HttpPost]
public void Post([FromBody] string value)
{
}

// PUT api/values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}

// DELETE api/values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}
Loading