2018-10-06 14:16:42 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using LaDOSE.Business.Interface;
|
|
|
|
|
|
using LaDOSE.Entity;
|
|
|
|
|
|
using LaDOSE.Entity.Context;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
namespace LaDOSE.Business.Service
|
|
|
|
|
|
{
|
2018-10-07 03:03:38 +02:00
|
|
|
|
public class GameService : BaseService<Game> ,IGameService
|
2018-10-06 14:16:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
|
2018-10-07 03:03:38 +02:00
|
|
|
|
public GameService(LaDOSEDbContext context) : base(context)
|
2018-10-06 14:16:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-16 12:22:52 +01:00
|
|
|
|
public override Game AddOrUpdate(Game entity)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (entity.Order == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
entity.Order = GetNextFreeOrder();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return base.AddOrUpdate(entity);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-07 03:03:38 +02:00
|
|
|
|
public override IEnumerable<Game> GetAll()
|
2018-10-06 14:16:42 +02:00
|
|
|
|
{
|
2018-10-07 15:15:11 +02:00
|
|
|
|
return _context.Game.Include(e => e.Seasons).ThenInclude(e=>e.Season).ToList();
|
2018-10-06 14:16:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-03-16 12:22:52 +01:00
|
|
|
|
public int GetNextFreeOrder()
|
|
|
|
|
|
{
|
|
|
|
|
|
int nextFreeOrder = _context.Game.Max(e => e.Order);
|
|
|
|
|
|
return ++nextFreeOrder;
|
|
|
|
|
|
}
|
2018-10-06 14:16:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|