feature/client-template #2

Merged
homeburger merged 27 commits from feature/client-template into main 2026-03-14 23:10:46 -05:00
2 changed files with 60 additions and 0 deletions
Showing only changes of commit 509b8b003c - Show all commits

View 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; }
}

View 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;
}
}
}