Refactor: the project is now divided into a more clear structure, with **Infrastructure** and **Application** layers added. Refactor: configurations are split into sections for different layers. Fix: now EF Core related operations, such as migration, should be invoked in `OptixServe.Infrastructure`, with config file and data dir passed into `dotnet ef` command. See `OptixServe.Infrastructure/Utilites/DesignTimeDbContextFactory.cs` for details. Fix: EF migrations are ignored in gitignore on purpose in early development.
32 lines
749 B
C#
32 lines
749 B
C#
using OptixServe.Core.Models;
|
|
using OptixServe.Infrastructure.Data;
|
|
|
|
namespace OptixServe.Application.Services;
|
|
|
|
public interface IUserService
|
|
{
|
|
IEnumerable<User> GetUsers();
|
|
User? GetUserById(string id);
|
|
User? GetUserByUsername(string username);
|
|
}
|
|
|
|
public class UserService(AppDbContext dbContext) : IUserService
|
|
{
|
|
private readonly AppDbContext _dbContext = dbContext;
|
|
|
|
public User? GetUserById(string id)
|
|
{
|
|
return _dbContext.Users.FirstOrDefault(u => u.Id == id);
|
|
}
|
|
|
|
public User? GetUserByUsername(string username)
|
|
{
|
|
return _dbContext.Users.FirstOrDefault(u => u.UserName == username);
|
|
}
|
|
|
|
public IEnumerable<User> GetUsers()
|
|
{
|
|
return _dbContext.Users.AsEnumerable();
|
|
}
|
|
}
|