Commit Debut de rework

This commit is contained in:
2022-03-19 22:54:55 +01:00
parent aebc60d17f
commit ab02d292da
24 changed files with 234 additions and 212 deletions

View File

@@ -1,18 +0,0 @@
using LaDOSE.Business.Interface;
using LaDOSE.Business.Service;
using LaDOSE.Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace LaDOSE.Api.Controllers
{
[Authorize]
[Route("api/[controller]")]
[Produces("application/json")]
public class SeasonController : GenericController<ISeasonService,Season>
{
public SeasonController(ISeasonService service) : base(service)
{
}
}
}

View File

@@ -44,18 +44,6 @@ namespace LaDOSE.Api.Controllers
return null;
}
//[HttpPost("GetResults")]
//public async Task<TournamentsResultDTO> GetResults([FromBody] List<int> ids)
//{
// if (ids == null)
// {
// throw new Exception("Invalid arguments");
// }
// var tournamentsResult = await _service.GetTournamentsResult(ids);
// return _mapper.Map<TournamentsResultDTO>(tournamentsResult);
//}
}

View File

@@ -30,6 +30,7 @@ using LaDOSE.Business.Provider.ChallongProvider;
using LaDOSE.Business.Provider.SmashProvider;
using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress;
using Result = LaDOSE.Entity.Challonge.Result;
namespace LaDOSE.Api
{
@@ -146,7 +147,6 @@ namespace LaDOSE.Api
services.AddScoped<IUserService, UserService>();
services.AddScoped<IGameService, GameService>();
services.AddScoped<IEventService, EventService>();
services.AddScoped<ISeasonService, SeasonService>();
services.AddScoped<IWordPressService, WordPressService>();
services.AddScoped<ITodoService, TodoService>();
services.AddScoped<ITournamentService, TournamentService>();

View File

@@ -19,14 +19,15 @@ namespace LaDOSE.DesktopApp
{
#if DEBUG
MessageBox.Show("WAITING IN DEBUG MODE");
MessageBox.Show("WAITING IN DEBUG MODE");
#endif
base.OnStartup(e);
var settings = new CefSettings();
settings.SetOffScreenRenderingBestPerformanceArgs();
Cef.Initialize(settings);
base.OnStartup(e);
}

View File

@@ -26,7 +26,6 @@ namespace LaDOSE.DesktopApp
container.Singleton<IWindowManager, WindowManager>();
container.Singleton<RestService>();
container.PerRequest<ShellViewModel>();

View File

@@ -31,7 +31,7 @@ namespace LaDOSE.DesktopApp.ViewModels
this.AppIcon = BitmapFrame.Create(Application.GetResourceStream(new Uri("/LaDOSE.DesktopApp;component/Resources/64x64.png",
UriKind.RelativeOrAbsolute)).Stream);
var appSettings = ConfigurationManager.AppSettings;
string url = (string)appSettings["ApiUri"];
string user = (string)appSettings["ApiUser"];
@@ -41,9 +41,10 @@ namespace LaDOSE.DesktopApp.ViewModels
restService.UpdatedJwtEvent += TokenUpdate;
restService.Connect(uri, user, password);
base.OnInitialize();
ActivateItem(new TournamentResultViewModel(IoC.Get<RestService>()));
}
private void TokenUpdate(object sender, UpdatedJwtEventHandler e)
@@ -56,7 +57,7 @@ namespace LaDOSE.DesktopApp.ViewModels
public void LoadEvent()
{
ActivateItem(new WordPressViewModel(IoC.Get<RestService>()));
ActivateItem(new WordPressViewModel(IoC.Get<RestService>()));
}
public void LoadGames()
{

View File

@@ -344,7 +344,13 @@ namespace LaDOSE.DesktopApp.ViewModels
int columns = 0;
foreach (var game in Results.Games)
{
List<ResultDTO> enumerable = Results.Results.Where(r => r.GameId == game.Id).ToList();
List<string> top3 = enumerable.OrderBy(e => e.Rank).Take(3).Select(e => e.Player).ToList();
if (top3.Count == 0)
{
continue;
}
if (columns % 2 == 0)
{
sb.Append("<tr>");
@@ -354,8 +360,7 @@ namespace LaDOSE.DesktopApp.ViewModels
"<span style=\"color: #ff0000;\">" +
$"<strong>{game.LongName} ({Results.Results.Count(e => e.GameId == game.Id)} participants) :</strong>" +
"</span>");
List<ResultDTO> enumerable = Results.Results.Where(r => r.GameId == game.Id).ToList();
List<string> top3 = enumerable.OrderBy(e => e.Rank).Take(3).Select(e => e.Player).ToList();
if (top3.Count >= 3)
{
sb.AppendLine($"<br> 1/ {top3[0]}<br> 2/ {top3[1]}<br> 3/ {top3[2]} <br>");

View File

@@ -1,4 +1,5 @@
using LaDOSE.Entity.Challonge;
using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore;
@@ -8,19 +9,25 @@ namespace LaDOSE.Entity.Context
{
public DbSet<Game> Game { get; set; }
public DbSet<ApplicationUser> ApplicationUser { get; set; }
public DbSet<Season> Season { get; set; }
public DbSet<Event> Event { get; set; }
public DbSet<Todo> Todo { get; set; }
#region WordPress
public DbSet<WPUser> WPUser { get; set; }
public DbSet<WPEvent> WPEvent { get; set; }
public DbSet<WPBooking> WPBooking { get; set; }
#endregion
#region Tournament
public DbSet<Player> Player { get; set; }
public DbSet<Event> Event { get; set; }
public DbSet<Tournament> Tournament { get; set; }
public DbSet<Result> Result { get; set; }
#endregion
public DbSet<SeasonGame> SeasonGame { get; set; }
public DbSet<EventGame> EventGame { get; set; }
public DbSet<ChallongeParticipent> ChallongeParticipent { get; set; }
public DbSet<ChallongeTournament> ChallongeTournament { get; set; }
@@ -36,43 +43,43 @@ namespace LaDOSE.Entity.Context
modelBuilder.Entity<Event>()
.HasOne(s => s.Season)
.WithMany(p => p.Event)
.HasForeignKey(fk => fk.SeasonId);
//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 });
//#region SeasonGame
//modelBuilder.Entity<SeasonGame>()
// .HasKey(t => new { t.SeasonId, t.GameId });
modelBuilder.Entity<SeasonGame>()
.HasOne(pt => pt.Season)
.WithMany(p => p.Games)
.HasForeignKey(pt => pt.SeasonId);
//modelBuilder.Entity<SeasonGame>()
// .HasOne(pt => pt.Season)
// .WithMany(p => p.Games)
// .HasForeignKey(pt => pt.SeasonId);
modelBuilder.Entity<SeasonGame>()
.HasOne(pt => pt.Game)
.WithMany(p => p.Seasons)
.HasForeignKey(pt => pt.GameId);
#endregion
//modelBuilder.Entity<SeasonGame>()
// .HasOne(pt => pt.Game)
// .WithMany(p => p.Seasons)
// .HasForeignKey(pt => pt.GameId);
//#endregion
#region EventGame
//#region EventGame
modelBuilder.Entity<EventGame>()
.HasKey(t => new { t.EventId, t.GameId });
//modelBuilder.Entity<EventGame>()
// .HasKey(t => new { t.EventId, t.GameId });
modelBuilder.Entity<EventGame>()
.HasOne(pt => pt.Event)
.WithMany(p => p.Games)
.HasForeignKey(pt => pt.EventId);
//modelBuilder.Entity<EventGame>()
// .HasOne(pt => pt.Event)
// .WithMany(p => p.Games)
// .HasForeignKey(pt => pt.EventId);
modelBuilder.Entity<EventGame>()
.HasOne(pt => pt.Game)
.WithMany(p => p.Events)
.HasForeignKey(pt => pt.GameId);
#endregion
//modelBuilder.Entity<EventGame>()
// .HasOne(pt => pt.Game)
// .WithMany(p => p.Events)
// .HasForeignKey(pt => pt.GameId);
//#endregion
#region WordPress WPBooking

View File

@@ -1,22 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LaDOSE.Entity
{
public class Event : Context.Entity
{
//[Key]
//public int Id { get; set; }
public string Name { get; set; }
public DateTime Date { get; set; }
public int SeasonId { get; set; }
public Season Season { get; set; }
public bool Ranking { get; set; }
public virtual IEnumerable<EventGame> Games { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
namespace LaDOSE.Entity
{
public class EventGame
{
public int EventId { get; set; }
public Event Event { get; set; }
public int GameId { get; set; }
public Game Game { get; set; }
public int? ChallongeId { get; set; }
public string ChallongeUrl { get; set; }
}
}

View File

@@ -13,16 +13,8 @@ namespace LaDOSE.Entity
public string WordPressTagOs { get; set; }
public int? SmashId { get; set; }
public virtual IEnumerable<SeasonGame> Seasons { get; set; }
public virtual IEnumerable<EventGame> Events { get; set; }
}
public class SmashParticipent : Context.Entity
{
public string Name { get; set; }
public string Tag { get; set; }
public int? SmashId{ get; set; }
}
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace LaDOSE.Entity
{
public class Season : Context.Entity
{
public string Name { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public virtual IEnumerable<SeasonGame> Games { get; set; }
public virtual IEnumerable<Event> Event { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
namespace LaDOSE.Entity
{
public class SeasonGame
{
public int GameId { get; set; }
public Game Game { get; set; }
public int SeasonId { get; set; }
public Season Season { get; set; }
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
namespace LaDOSE.Entity
{
/// <summary>
/// Represent a Event (Multiple tournaments)
/// </summary>
public class Event : Context.Entity
{
public Event()
{
}
public Event(string name,int? smashId)
{
Name = name;
SmashId = smashId;
}
public String Name { get; set; }
public int? SmashId { get; set; }
public DateTime Date { get; set; }
public List<Tournament> Tournaments { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Security.Cryptography.X509Certificates;
namespace LaDOSE.Entity
{
public class Player : Context.Entity
{
public Player()
{
}
public Player(string name, int? challongeId, int? smashId)
{
this.Name = name;
ChallongeId = challongeId;
SmashId = smashId;
}
public String SmashName { get; set; }
public String Name { get; set; }
public int? ChallongeId {get;set;}
public int? SmashId {get;set;}
public Boolean IsChallonge => ChallongeId.HasValue;
}
}

View File

@@ -0,0 +1,27 @@
namespace LaDOSE.Entity
{
public class Result : Context.Entity
{
public Result(Player player, int point, int rank, Tournament tournament)
{
Player = player;
Point = point;
Rank = rank;
Tournament = tournament;
}
public Result()
{
}
public int PlayerId { get; set; }
public Player Player { get; set; }
public int IdTournament { get; set; }
public Tournament Tournament{ get; set; }
public int Point { get; set; }
public int Rank { get; set; }
}
}

View File

@@ -0,0 +1,25 @@
using System;
namespace LaDOSE.Entity
{
public class Tournament : Context.Entity
{
public Tournament()
{
}
public Tournament(string name, int challongeId, int smashId)
{
Name = name;
ChallongeId = challongeId;
SmashId = smashId;
}
public String Name { get; set; }
public int ChallongeId {get;set;}
public int SmashId {get;set;}
public int? GameId {get;set;}
public Game Game { get; set; }
}
}

View File

@@ -2,8 +2,8 @@
namespace LaDOSE.Business.Interface
{
public interface ISeasonService : IBaseService<Season>
{
//public interface ISeasonService : IBaseService<Season>
//{
}
//}
}

View File

@@ -12,5 +12,6 @@ namespace LaDOSE.Business.Interface
Task<TournamentsResult> GetTournamentsResult(List<int> ids);
Task<TournamentsResult> GetSmashResult(string tournamentSlug);
}
}

View File

@@ -66,26 +66,26 @@ namespace LaDOSE.Business.Provider.SmashProvider
id
name,
state,
videogame {
id,
name,
displayName
}
standings(query: {page:0,perPage:500}){
nodes{
id,
player{
id,
gamerTag,
user {
id,
name,
player {
id
}
}
}
placement
videogame {
id,
name,
displayName
}
standings(query: {page:0,perPage:500}){
nodes{
id,
player{
id,
gamerTag,
user {
id,
name,
player {
id
}
}
}
placement
}
}

View File

@@ -20,23 +20,24 @@ namespace LaDOSE.Business.Service
this._challongeProvider = challongeProvider;
}
public override Event GetById(int id)
{
return _context.Event.Include(e => e.Season).Include(e => e.Games).ThenInclude(e => e.Game)
.FirstOrDefault(e => e.Id == id);
}
//public override Event GetById(int id)
//{
// re
// //return _context.Event.Include(e => e.Season).Include(e => e.Games).ThenInclude(e => e.Game)
// // .FirstOrDefault(e => e.Id == id);
//}
public override Event Create(Event e)
{
if (e.Id != 0)
{
throw new Exception("Id is invalid");
}
//public override Event Create(Event e)
//{
// if (e.Id != 0)
// {
// throw new Exception("Id is invalid");
// }
var eventAdded = _context.Event.Add(e);
_context.SaveChanges();
return eventAdded.Entity;
}
// var eventAdded = _context.Event.Add(e);
// _context.SaveChanges();
// return eventAdded.Entity;
//}
}
}

View File

@@ -27,7 +27,7 @@ namespace LaDOSE.Business.Service
public override IEnumerable<Game> GetAll()
{
return _context.Game.Include(e => e.Seasons).ThenInclude(e=>e.Season).ToList();
return _context.Game.ToList();
}
public int GetNextFreeOrder()

View File

@@ -1,13 +0,0 @@
using LaDOSE.Business.Interface;
using LaDOSE.Entity;
using LaDOSE.Entity.Context;
namespace LaDOSE.Business.Service
{
public class SeasonService : BaseService<Season>, ISeasonService
{
public SeasonService(LaDOSEDbContext context) : base(context)
{
}
}
}

View File

@@ -11,6 +11,7 @@ using LaDOSE.Entity.Context;
using LaDOSE.Entity.Wordpress;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Result = LaDOSE.Entity.Challonge.Result;
namespace LaDOSE.Business.Service
{
@@ -120,18 +121,18 @@ namespace LaDOSE.Business.Service
var Top8 = tournament.Participents.Where(p => p.Rank > 4 && p.Rank < 9).ToList();
var Top16 = tournament.Participents.Where(p => p.Rank > 8 && p.Rank <= 16).ToList();
result.Results.Add(new Result(first.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.FirstPoint,first.Rank??0));
result.Results.Add(new Result(first.Name, tournament.Game?.Id??0, tournament.ChallongeId, tournament.Url, currentRule.FirstPoint,first.Rank??0));
lesSacs.Remove(first);
result.Results.Add(new Result(second.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.SecondPoint, second.Rank ?? 0));
result.Results.Add(new Result(second.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.SecondPoint, second.Rank ?? 0));
lesSacs.Remove(second);
thirdFourth.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url,
result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url,
currentRule.ThirdFourthPoint, r.Rank ?? 0)));
thirdFourth.ForEach(p => lesSacs.Remove(p));
if (currentRule.Top8Point != 0)
{
Top8.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.Top8Point, r.Rank ?? 0)));
result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top8Point, r.Rank ?? 0)));
Top8.ForEach(p => lesSacs.Remove(p));
}
@@ -139,17 +140,21 @@ namespace LaDOSE.Business.Service
{
Top16.ForEach(r =>
result.Results.Add(
new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url, currentRule.Top16Point, r.Rank ?? 0)));
new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url, currentRule.Top16Point, r.Rank ?? 0)));
Top16.ForEach(p => lesSacs.Remove(p));
}
lesSacs.ForEach(r =>
result.Results.Add(new Result(r.Name, tournament.Game.Id, tournament.ChallongeId, tournament.Url,
result.Results.Add(new Result(r.Name, tournament.Game?.Id ?? 0, tournament.ChallongeId, tournament.Url,
currentRule.Participation, r.Rank ?? 0)));
}
result.Games = tournaments.Select(e => e.Game).Distinct((game, game1) => game.Name == game1.Name).ToList();
result.Games = tournaments.Select(e => e.Game).Distinct((game, game1) => game.Name == game1.Name).Where(e=>e!=null).ToList();
if (result.Games == null)
{
result.Games = new List<Game>();
}
result.Games.Add(new Game() {Id = 0, Order = 9999,Name = "UNKNOW"});
return result;
}
@@ -236,6 +241,8 @@ namespace LaDOSE.Business.Service
return await Task.FromResult(result);
}
/// <summary>
/// Check if the tournament exist in database otherwise call Challonge.
/// </summary>
@@ -271,6 +278,10 @@ namespace LaDOSE.Business.Service
return tournaments;
}
public Task<object> GetSmashTop(string tournamentSlug, string eventId,int playerCount)
{
throw new NotImplementedException();
}
private bool TournamentExist(int idTournament)
{
return this._context.ChallongeTournament.Any(e => e.ChallongeId == idTournament);