38 lines
1000 B
C#
38 lines
1000 B
C#
using GroupService.Domain.Entities;
|
|
using GroupService.Domain.IReposities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace GroupService.Infrastructure.Reposities
|
|
{
|
|
public class GroupReposity : IGroupReposity
|
|
{
|
|
private readonly GroupDbContext db;
|
|
|
|
public GroupReposity(GroupDbContext db)
|
|
{
|
|
this.db = db;
|
|
}
|
|
|
|
public Group Create(Group group)
|
|
{
|
|
db.Groups.Add(group);
|
|
return group;
|
|
}
|
|
|
|
public async Task<Group?> FindByIdAsync(Guid id)
|
|
{
|
|
return await db.Groups.FirstOrDefaultAsync(x => x.Id == id);
|
|
}
|
|
|
|
public async Task<IEnumerable<Group>> FindByMasterIdAsync(Guid userId)
|
|
{
|
|
return await db.Groups.Where(x => x.GroupMaster == userId).ToListAsync();
|
|
}
|
|
|
|
public async Task<IEnumerable<Group>> FindByNameAsync(string name)
|
|
{
|
|
return await db.Groups.Where(x => x.Name == name).ToListAsync();
|
|
}
|
|
}
|
|
}
|