-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTeamEngine.cs
96 lines (81 loc) · 3.23 KB
/
TeamEngine.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using Business.Engine.Interfaces;
using Core.ApplicationCore.UnitOfWork;
using Core.Common.DTOs.Team;
using Data.DataAccessLayer.Context;
using Data.DataAccessLayer.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Business.Engine.Engines
{
public class TeamEngine : ITeamEngine
{
private readonly IUnitOfWork<CRUDAppContext> _unitOfWork;
public TeamEngine(IUnitOfWork<CRUDAppContext> unitOfWork)
{
_unitOfWork = unitOfWork;
}
public async Task<bool> AddTeam(TeamDto model)
{
Team team = await _unitOfWork.GetRepository<Team>().AddAsync(new Team
{
Name = model.Name,
IsPaidEntryFee = model.IsPaidEntryFee,
NumberOfWinWorldChamp = model.NumberOfWonWorldChampionships,
YearOfFoundation = model.YearOfFoundation
});
return team != null && team.TeamId != 0;
}
public async Task<bool> TeamIsExists(string teamName) =>
await _unitOfWork.GetRepository<Team>().FindAsync(x => string.Equals(x.Name, teamName, StringComparison.CurrentCultureIgnoreCase)) != null;
public async Task<bool> TeamIsExists(int id, string teamName) =>
await _unitOfWork.GetRepository<Team>().FindAsync(x => x.TeamId != id && string.Equals(x.Name, teamName, StringComparison.CurrentCultureIgnoreCase)) != null;
public List<TeamListItemDto> GetAllTeam()
{
IEnumerable<Team> teams =
_unitOfWork.GetRepository<Team>().Filter(null, x => x.OrderBy(y => y.Name));
return teams.Select(x => new TeamListItemDto
{
Id = x.TeamId,
Name = x.Name,
IsPaidEntryFee = x.IsPaidEntryFee,
NumberOfWonWorldChampionships = x.NumberOfWinWorldChamp,
YearOfFoundation = x.YearOfFoundation
}).ToList();
}
public TeamDto GetTeamById(int id)
{
Team team = _unitOfWork.GetRepository<Team>().FindAsync(x => x.TeamId == id).Result;
if (team == null)
{
return new TeamDto();
}
return new TeamDto
{
Name = team.Name,
Id = team.TeamId,
NumberOfWonWorldChampionships = team.NumberOfWinWorldChamp,
YearOfFoundation = team.YearOfFoundation,
IsPaidEntryFee = team.IsPaidEntryFee
};
}
public async Task<bool> UpdateTeam(TeamDto model)
{
Team team = await _unitOfWork.GetRepository<Team>().UpdateAsync(new Team
{
TeamId = model.Id,
Name = model.Name,
NumberOfWinWorldChamp = model.NumberOfWonWorldChampionships,
YearOfFoundation = model.YearOfFoundation,
IsPaidEntryFee = model.IsPaidEntryFee
});
return team != null;
}
public bool DeleteTeamById(int id)
{
Task<int> result = _unitOfWork.GetRepository<Team>().DeleteAsync(new Team { TeamId = id });
return Convert.ToBoolean(result.Result);
}
}
}