37 lines
967 B
C#
37 lines
967 B
C#
namespace MyOffice.Data.Repositories.Item;
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MyOffice.Data.Models.Items;
|
|
|
|
public class ItemGlobalRepository : AppRepository<ItemGlobal>, IItemGlobalRepository
|
|
{
|
|
public ItemGlobal? Get(Guid id)
|
|
{
|
|
return _context.ItemGlobals.FirstOrDefault(x => x.Id == id);
|
|
}
|
|
|
|
public ItemGlobal? GetByName(string name)
|
|
{
|
|
return _context.ItemGlobals.FirstOrDefault(x => x.Name == name);
|
|
}
|
|
|
|
public bool Add(ItemGlobal itemGlobal)
|
|
{
|
|
return AddBase(itemGlobal) > 0;
|
|
}
|
|
|
|
public List<ItemGlobal> GetAvailableToUser(Guid userId)
|
|
{
|
|
return _context.Motions
|
|
.Include(x => x.Item)
|
|
.ThenInclude(x => x.ItemGlobal)
|
|
.ThenInclude(x => x.Items)
|
|
.ThenInclude(x => x.Category)
|
|
.Where(x => x.Account.AccessRights!.Any(a => a.UserId == userId))
|
|
.Where(x => x.Item.ItemGlobal.Items.All(g => g.Category!.UserId != userId))
|
|
.Select(x => x.Item.ItemGlobal)
|
|
.GroupBy(x => x.Id)
|
|
.Select(x => x.First())
|
|
.ToList();
|
|
}
|
|
} |