initial commit
This commit is contained in:
34
Infrastructure/Repositories/KillRepository.cs
Normal file
34
Infrastructure/Repositories/KillRepository.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Application.Interfaces.Repositories;
|
||||
using Domain.Entities;
|
||||
using Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Repositories;
|
||||
|
||||
public class KillRepository(AppDbContext context) : IKillRepository
|
||||
{
|
||||
public IEnumerable<Kill> GetAllKills()
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
return context.Kills.AsNoTracking();
|
||||
}
|
||||
|
||||
public bool TryGetKillById(int id, out Kill? kill)
|
||||
{
|
||||
kill = context.Kills.FirstOrDefault(k => k.Id == id);
|
||||
|
||||
return kill != null;
|
||||
}
|
||||
|
||||
public void AddKill(Kill kill)
|
||||
{
|
||||
context.Kills.Add(kill);
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
public bool RemoveKill(Kill kill)
|
||||
{
|
||||
context.Kills.Remove(kill);
|
||||
return context.SaveChanges() > 0;
|
||||
}
|
||||
}
|
||||
33
Infrastructure/Repositories/UserRepository.cs
Normal file
33
Infrastructure/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Application.Interfaces.Repositories;
|
||||
using Domain.Entities;
|
||||
using Infrastructure.Database;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Repositories;
|
||||
|
||||
public class UserRepository(AppDbContext context) : IUserRepository
|
||||
{
|
||||
public IEnumerable<User> GetAllUsers()
|
||||
{
|
||||
context.Database.EnsureCreated();
|
||||
return context.Users.AsNoTracking();
|
||||
}
|
||||
|
||||
public bool TryGetUserById(int id, out User? user)
|
||||
{
|
||||
user = context.Users.FirstOrDefault(u => u.Id == id);
|
||||
return user != null;
|
||||
}
|
||||
|
||||
public bool AddUser(User user)
|
||||
{
|
||||
context.Users.Add(user);
|
||||
return context.SaveChanges() != 0;
|
||||
}
|
||||
|
||||
public bool UpdateUser(User user)
|
||||
{
|
||||
context.Users.Update(user);
|
||||
return context.SaveChanges() != 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user