refactoring
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
namespace MyOffice.Data.Repositories.Item;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
public class ItemRepository : AppRepository<Item>, IItemRepository
|
||||
{
|
||||
public List<Item> GetAll(Guid userId)
|
||||
{
|
||||
return _context.Items
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.ItemGlobal)
|
||||
.Where(x => x.Category.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<Item> GetByCategory(Guid userId, Guid categoryId)
|
||||
{
|
||||
return _context.Items
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.ItemGlobal)
|
||||
.Where(x => x.Category.UserId == userId && x.CategoryId == categoryId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Item? GetByGlobal(Guid userId, Guid globalMotionId)
|
||||
{
|
||||
return _context.Items
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.ItemGlobal)
|
||||
.FirstOrDefault(x => x.Category.UserId == userId && x.ItemGlobalId == globalMotionId);
|
||||
}
|
||||
|
||||
public bool Update(Item item)
|
||||
{
|
||||
return base.UpdateBase(item) > 0;
|
||||
}
|
||||
|
||||
public bool Add(Item item)
|
||||
{
|
||||
return base.AddBase(item) > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user