Skip to content

Commit 734f1c8

Browse files
Sullivan008Kozák Péter
authored and
Kozák Péter
committed
ASP.NET MVC Core - Formula One Project Initialize
0 parents  commit 734f1c8

File tree

300 files changed

+96127
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

300 files changed

+96127
-0
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\Business.Entities\Business.Entities.csproj" />
13+
<ProjectReference Include="..\Core.Common\Core.Common.csproj" />
14+
<ProjectReference Include="..\Data.DataAccessLayer\Data.DataAccessLayer.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using Business.Engine.BusinessEngines.Interfaces;
2+
using Business.Entities.DataBaseEntities;
3+
using Core.Common.Data.DTOs;
4+
using Core.Common.Utils;
5+
using Data.DataAccessLayer.Context;
6+
using Data.DataAccessLayer.DataRepositories.Interfaces;
7+
using Data.DataAccessLayer.DataRepositories.Repositories;
8+
using System.Collections.Generic;
9+
using System.Linq;
10+
using System.Threading.Tasks;
11+
12+
namespace Business.Engine.BusinessEngines.Engines
13+
{
14+
public class TeamEngine : ITeamEngine
15+
{
16+
private readonly ITeamRepository _teamRepository;
17+
18+
public FormulaContext _ctx { get; set; }
19+
20+
/// <summary>
21+
/// Konstruktor
22+
/// </summary>
23+
public TeamEngine()
24+
{
25+
_teamRepository = new TeamRepository();
26+
}
27+
28+
public async Task<bool> AddTeam(TeamDTO teamDTO)
29+
{
30+
_teamRepository._ctx = _ctx;
31+
32+
Team insertedTeam = await _teamRepository.Add(MapTeamDTOToTeam(teamDTO));
33+
34+
if (insertedTeam != null && insertedTeam?.TeamID != 0)
35+
{
36+
return true;
37+
}
38+
39+
return false;
40+
}
41+
42+
public async Task<List<TeamDTO>> GetAllTeam()
43+
{
44+
_teamRepository._ctx = _ctx;
45+
46+
return MapTeamToTeamDTO((await _teamRepository.GetAllTeam()).ToList());
47+
}
48+
49+
public TeamDTO GetTeamByID(int id)
50+
{
51+
_teamRepository._ctx = _ctx;
52+
53+
TeamDTO foundTeam = MapTeamToTeamDTO(_teamRepository.GetTeamByID(id).Result);
54+
55+
if (foundTeam != null && foundTeam?.TeamID != 0)
56+
{
57+
return foundTeam;
58+
}
59+
else
60+
{
61+
return new TeamDTO();
62+
}
63+
}
64+
65+
public async Task<bool> UpdateTeam(TeamDTO teamDTO)
66+
{
67+
_teamRepository._ctx = _ctx;
68+
69+
Team updatedTeam = await _teamRepository.Update(MapTeamDTOToTeam(teamDTO));
70+
71+
if(updatedTeam != null)
72+
{
73+
return true;
74+
}
75+
76+
return false;
77+
}
78+
79+
public async Task<bool> DeleteTeamByID(int id)
80+
{
81+
_teamRepository._ctx = _ctx;
82+
83+
Team deletedTeam = await _teamRepository.Delete(new Team() { TeamID = id });
84+
85+
if(deletedTeam != null && deletedTeam?.TeamID != 0)
86+
{
87+
return true;
88+
}
89+
90+
return false;
91+
}
92+
93+
#region HELPER Methods
94+
private List<TeamDTO> MapTeamToTeamDTO(List<Team> teams)
95+
{
96+
List<TeamDTO> teamDTOs = new List<TeamDTO>();
97+
98+
foreach (Team item in teams)
99+
{
100+
TeamDTO dto = new TeamDTO();
101+
102+
PropertyMapper.MapProperties(item, dto);
103+
104+
teamDTOs.Add(dto);
105+
}
106+
107+
return teamDTOs;
108+
}
109+
110+
private Team MapTeamDTOToTeam(TeamDTO teamDTO)
111+
{
112+
Team team = new Team();
113+
114+
PropertyMapper.MapProperties<TeamDTO, Team>(teamDTO, team);
115+
116+
return team;
117+
}
118+
119+
private TeamDTO MapTeamToTeamDTO(Team team)
120+
{
121+
TeamDTO teamDTO = new TeamDTO();
122+
123+
PropertyMapper.MapProperties<Team, TeamDTO>(team, teamDTO);
124+
125+
return teamDTO;
126+
}
127+
#endregion
128+
}
129+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using Business.Engine.BusinessEngines.Interfaces;
2+
using Business.Entities.DataBaseEntities;
3+
using Core.Handlers.BackEndExceptionHandler;
4+
using Microsoft.AspNetCore.Identity;
5+
using System;
6+
using System.Threading.Tasks;
7+
8+
namespace Business.Engine.BusinessEngines.Engines
9+
{
10+
public class UserEngine : IUserEngine
11+
{
12+
public async Task<bool?> Register(UserManager<AppUser> userManager, string userName, string password)
13+
{
14+
AppUser user = await userManager.FindByNameAsync(userName);
15+
16+
try
17+
{
18+
if(user != null)
19+
{
20+
return false;
21+
}
22+
else
23+
{
24+
user = new AppUser();
25+
user.UserName = userName;
26+
user.Email = $"{userName}@test.com";
27+
28+
IdentityResult result = await userManager.CreateAsync(user, password);
29+
30+
if(result.Succeeded)
31+
{
32+
return true;
33+
}
34+
else
35+
{
36+
return null;
37+
}
38+
}
39+
}
40+
catch(Exception ex)
41+
{
42+
new BackEndException<Exception>(ex).
43+
ExceptionOperations("Hiba a felhasználó regisztrálása során!");
44+
45+
return null;
46+
}
47+
}
48+
49+
public async Task<bool> Login(SignInManager<AppUser> signInManager, string userName, string password)
50+
{
51+
var result = await signInManager.PasswordSignInAsync(userName, password, false, false);
52+
53+
if(result.Succeeded)
54+
{
55+
return true;
56+
}
57+
else
58+
{
59+
return false;
60+
}
61+
}
62+
public async Task Logout(SignInManager<AppUser> signInManager)
63+
{
64+
await signInManager.SignOutAsync();
65+
}
66+
}
67+
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Business.Entities.DataBaseEntities;
2+
using Core.Common.Data.DTOs;
3+
using Data.DataAccessLayer.Context;
4+
using System.Collections.Generic;
5+
using System.Threading.Tasks;
6+
7+
namespace Business.Engine.BusinessEngines.Interfaces
8+
{
9+
public interface ITeamEngine
10+
{
11+
FormulaContext _ctx { get; set; }
12+
13+
Task<List<TeamDTO>> GetAllTeam();
14+
15+
TeamDTO GetTeamByID(int id);
16+
17+
Task<bool> AddTeam(TeamDTO team);
18+
19+
Task<bool> UpdateTeam(TeamDTO team);
20+
21+
Task<bool> DeleteTeamByID(int id);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Business.Entities.DataBaseEntities;
2+
using Microsoft.AspNetCore.Identity;
3+
using System.Threading.Tasks;
4+
5+
namespace Business.Engine.BusinessEngines.Interfaces
6+
{
7+
public interface IUserEngine
8+
{
9+
Task<bool?> Register(UserManager<AppUser> userManager, string userName, string password);
10+
11+
Task<bool> Login(SignInManager<AppUser> signInManager, string userName, string password);
12+
13+
Task Logout(SignInManager<AppUser> signInManager);
14+
}
15+
}

0 commit comments

Comments
 (0)