Files
Backend-Api/CompanyManagment.EFCore/Repository/LawRepository.cs

46 lines
1.4 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using _0_Framework.InfraStructure;
using Company.Domain.LawAgg;
using CompanyManagment.App.Contracts.Law;
using Microsoft.EntityFrameworkCore;
namespace CompanyManagment.EFCore.Repository;
public class LawRepository:RepositoryBase<long,Law>,ILawRepository
{
private readonly CompanyContext _context;
public LawRepository(CompanyContext context) : base(context)
{
_context = context;
}
public async Task<Law> GetWithItems(long id)
{
return await _context.Laws.Include(x => x.Items).FirstOrDefaultAsync(x => x.id == id);
}
public async Task<List<Law>> GetActive()
{
return await _context.Laws.Where(x => x.IsActive).ToListAsync();
}
public async Task<LawViewModel> GetByType(LawType type)
{
return await _context.Laws.Where(x => x.Type == type && x.IsActive)
.Select(x => new LawViewModel
{
Id = x.id,
Title = x.Title,
IsActive = x.IsActive,
CreatedAt = x.CreationDate,
Items = x.Items.Select(i => new LawItemViewModel
{
Header = i.Header,
Details = i.Details,
OrderNumber = i.OrderNumber
}).OrderBy(i => i.OrderNumber).ToList()
}).FirstOrDefaultAsync();
}
}