add the new files dummyhead
All checks were successful
Build and Deploy API / build-and-deploy (push) Successful in 7s

This commit is contained in:
2026-03-14 11:36:22 -05:00
parent 0da09d7594
commit 509b8b003c
2 changed files with 60 additions and 0 deletions

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