This commit is contained in:
39
api/src/Services/UserService.cs
Normal file
39
api/src/Services/UserService.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using agologumApi.Models;
|
||||
|
||||
namespace agologumApi.Services;
|
||||
|
||||
public class UserService {
|
||||
|
||||
private readonly AppDbContext db_;
|
||||
|
||||
public UserService(AppDbContext db) {
|
||||
db_ = db;
|
||||
}
|
||||
|
||||
public async Task<List<User>> GetAll() {
|
||||
return await db_.Users.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<User?> Get(int id) {
|
||||
return await db_.Users.FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<User?> Get(string name) {
|
||||
return await db_.Users.FirstOrDefaultAsync(u => u.UserName == name);
|
||||
}
|
||||
|
||||
public async Task<bool> Delete(int id) {
|
||||
User? User = await db_.Users.FindAsync(id);
|
||||
if(User != null) {
|
||||
db_.Users.Remove(User);
|
||||
await db_.SaveChangesAsync();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user