Files
LaDOSE/LaDOSE.Src/LaDOSE.Service/Service/GameService.cs

44 lines
1.0 KiB
C#
Raw Normal View History

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
{
public class GameService : BaseService<Game> ,IGameService
2018-10-06 14:16:42 +02:00
{
public GameService(LaDOSEDbContext context) : base(context)
2018-10-06 14:16:42 +02: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;
}
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
}
public int GetNextFreeOrder()
{
int nextFreeOrder = _context.Game.Max(e => e.Order);
return ++nextFreeOrder;
}
2018-10-06 14:16:42 +02:00
}
}