Creation des Challonges a partir des Event WordPress
This commit is contained in:
@@ -9,5 +9,6 @@ namespace LaDOSE.Business.Interface
|
||||
Task<Boolean> GetLastTournament();
|
||||
string GetLastTournamentMessage();
|
||||
Task<TournamentResult> CreateTournament(string name, string url);
|
||||
Task<ParticipantResult> AddPlayer(int tournamentId, string userName);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,6 @@ namespace LaDOSE.Business.Interface
|
||||
{
|
||||
public interface IEventService : IBaseService<Event>
|
||||
{
|
||||
bool CreateChallonge(int dto);
|
||||
bool CreateChallonge(int eventId, int wpEventId);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using ChallongeCSharpDriver;
|
||||
using ChallongeCSharpDriver.Caller;
|
||||
using ChallongeCSharpDriver.Core.Objects;
|
||||
using ChallongeCSharpDriver.Core.Queries;
|
||||
using ChallongeCSharpDriver.Core.Results;
|
||||
using LaDOSE.Business.Interface;
|
||||
@@ -36,6 +37,14 @@ namespace LaDOSE.Business.Provider
|
||||
|
||||
}
|
||||
|
||||
public async Task<ParticipantResult> AddPlayer(int tournamentId, string userName)
|
||||
{
|
||||
var p = new ParticipantEntry(userName);
|
||||
var result = await new AddParticipantQuery(tournamentId, p).call(ApiCaller);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public async Task<Boolean> GetLastTournament()
|
||||
{
|
||||
try
|
||||
|
||||
@@ -33,9 +33,13 @@ namespace LaDOSE.Business.Service
|
||||
return eventAdded.Entity;
|
||||
}
|
||||
|
||||
public bool CreateChallonge(int dto)
|
||||
public bool CreateChallonge(int eventId,int wpEventId)
|
||||
{
|
||||
var currentEvent = _context.Event.Include(e=>e.Games).ThenInclude(e=>e.Game).FirstOrDefault(e=>e.Id == dto);
|
||||
var currentEvent = _context.Event.Include(e=>e.Games).ThenInclude(e=>e.Game).FirstOrDefault(e=>e.Id == eventId);
|
||||
var currentWpEvent = _context.WPEvent.Include(e => e.WPBookings).ThenInclude(e => e.WPUser).Where(e=>e.Id == wpEventId);
|
||||
var users = currentWpEvent.SelectMany(e => e.WPBookings.Select(u => u.WPUser));
|
||||
|
||||
var userNames = users.Select(e => e.Name).Distinct().ToList();
|
||||
if (currentEvent != null)
|
||||
{
|
||||
var games = currentEvent.Games.Select(e => e.Game);
|
||||
@@ -48,6 +52,19 @@ namespace LaDOSE.Business.Service
|
||||
var eventGame = currentEvent.Games.FirstOrDefault(e => e.GameId == game.Id);
|
||||
eventGame.ChallongeId = tournament.id;
|
||||
eventGame.ChallongeUrl = tournament.url;
|
||||
foreach (var userName in userNames)
|
||||
{
|
||||
try
|
||||
{
|
||||
_challongeProvider.AddPlayer(tournament.id, userName);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine($"Erreur d ajout sur {userName}" );
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
_context.Entry(eventGame).State = EntityState.Modified;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user