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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-20 19:36:15 +01:00
|
|
|
|
public int? GetIdByName(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _context.Game.FirstOrDefault(e => e.Name == name)?.Id ?? null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-10-07 03:03:38 +02:00
|
|
|
|
public override IEnumerable<Game> GetAll()
|
2018-10-06 14:16:42 +02:00
|
|
|
|
{
|
2022-03-19 22:54:55 +01:00
|
|
|
|
return _context.Game.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
|
|
|
|
}
|
|
|
|
|
|
}
|