add the new files dummyhead
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 7s
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 7s
This commit is contained in:
13
api/src/Data/AppDbContext.cs
Normal file
13
api/src/Data/AppDbContext.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
using agologumApi.Models;
|
||||||
|
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
public class AppDbContext : DbContext {
|
||||||
|
|
||||||
|
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public DbSet<User> Users { get; set; }
|
||||||
|
}
|
||||||
47
api/src/Services/UserService.cs
Normal file
47
api/src/Services/UserService.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
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> Create(User user) {
|
||||||
|
db_.Users.Add(user);
|
||||||
|
await db_.SaveChangesAsync();
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<User> Update(User user) {
|
||||||
|
db_.Users.Update(user);
|
||||||
|
await db_.SaveChangesAsync();
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
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