Creation des Challonges a partir des Event WordPress

This commit is contained in:
2018-10-08 23:33:18 +02:00
parent 70b5ea54f7
commit 39075051b2
10 changed files with 264 additions and 114 deletions

View File

@@ -33,10 +33,10 @@ namespace LaDOSE.Api.Controllers
}
[HttpGet("Generate/{dto}")]
public bool GenerateChallonge(int dto)
[HttpGet("Generate/{eventId}/{wpEventId}")]
public bool GenerateChallonge(int eventId, int wpEventId)
{
return _eventService.CreateChallonge(dto);
return _eventService.CreateChallonge(eventId, wpEventId);
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore;
using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore;
namespace LaDOSE.Entity.Context
{
@@ -8,6 +9,14 @@ namespace LaDOSE.Entity.Context
public DbSet<ApplicationUser> ApplicationUser { get; set; }
public DbSet<Season> Season { get; set; }
public DbSet<Event> Event { get; set; }
#region WordPress
public DbSet<WPUser> WPUser { get; set; }
public DbSet<WPEvent> WPEvent { get; set; }
public DbSet<WPBooking> WPBooking { get; set; }
#endregion
public DbSet<SeasonGame> SeasonGame { get; set; }
public DbSet<EventGame> EventGame { get; set; }
@@ -20,17 +29,18 @@ namespace LaDOSE.Entity.Context
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<SeasonGame>()
.HasKey(t => new { t.SeasonId, t.GameId });
modelBuilder.Entity<EventGame>()
.HasKey(t => new { t.EventId, t.GameId });
modelBuilder.Entity<Event>()
.HasOne(s => s.Season)
.WithMany(p => p.Event)
.HasForeignKey(fk => fk.SeasonId);
#region SeasonGame
modelBuilder.Entity<SeasonGame>()
.HasKey(t => new { t.SeasonId, t.GameId });
modelBuilder.Entity<SeasonGame>()
.HasOne(pt => pt.Season)
@@ -41,7 +51,12 @@ namespace LaDOSE.Entity.Context
.HasOne(pt => pt.Game)
.WithMany(p => p.Seasons)
.HasForeignKey(pt => pt.GameId);
#endregion
#region EventGame
modelBuilder.Entity<EventGame>()
.HasKey(t => new { t.EventId, t.GameId });
modelBuilder.Entity<EventGame>()
.HasOne(pt => pt.Event)
@@ -52,6 +67,23 @@ namespace LaDOSE.Entity.Context
.HasOne(pt => pt.Game)
.WithMany(p => p.Events)
.HasForeignKey(pt => pt.GameId);
#endregion
#region WordPress WPBooking
modelBuilder.Entity<WPBooking>()
.HasKey(t => new { t.WPEventId, t.WPUserId });
modelBuilder.Entity<WPBooking>()
.HasOne(pt => pt.WPEvent)
.WithMany(p => p.WPBookings)
.HasForeignKey(pt => pt.WPEventId);
modelBuilder.Entity<WPBooking>()
.HasOne(pt => pt.WPUser)
.WithMany(p => p.WPBookings)
.HasForeignKey(pt => pt.WPUserId);
#endregion
}
}

View File

@@ -0,0 +1,16 @@
namespace LaDOSE.Entity.Wordpress
{
public class WPBooking
{
//# WPEventId, WPUserId, Message, Meta
public int WPEventId { get; set; }
public WPEvent WPEvent { get; set; }
public int WPUserId { get; set; }
public WPUser WPUser { get; set; }
public string Message { get; set; }
public string Meta { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LaDOSE.Entity.Wordpress
{
public class WPEvent
{
[Key]
// Id, Name, Slug, Date
public int Id { get; set; }
public string Name { get; set; }
public string Slug { get; set; }
public string Date { get; set; }
public virtual IEnumerable<WPBooking> WPBookings { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LaDOSE.Entity.Wordpress
{
public class WPUser
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string WPUserId { get; set; }
public string WPMail { get; set; }
public virtual IEnumerable<WPBooking> WPBookings { get; set; }
}
}

View File

@@ -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);
}
}

View File

@@ -4,6 +4,6 @@ namespace LaDOSE.Business.Interface
{
public interface IEventService : IBaseService<Event>
{
bool CreateChallonge(int dto);
bool CreateChallonge(int eventId, int wpEventId);
}
}

View File

@@ -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

View File

@@ -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;
}