refactoring

This commit is contained in:
2023-06-22 10:01:27 +03:00
parent e9d4053e65
commit d549877567
116 changed files with 1216 additions and 11709 deletions
@@ -0,0 +1,12 @@
namespace MyOffice.Data.Repositories.Item;
using MyOffice.Data.Models.Items;
public interface IItemCategoryRepository
{
List<ItemCategory> GetAll(Guid userId);
bool Add(ItemCategory accountCategory);
ItemCategory? Get(Guid userId, Guid id);
bool Update(ItemCategory accountCategory);
bool Remove(ItemCategory accountCategory);
}
@@ -0,0 +1,10 @@
namespace MyOffice.Data.Repositories.Item;
using MyOffice.Data.Models.Items;
public interface IItemGlobalRepository
{
ItemGlobal? Get(Guid id);
ItemGlobal? GetByName(string name);
bool Add(ItemGlobal itemGlobal);
}
@@ -0,0 +1,13 @@
namespace MyOffice.Data.Repositories.Item;
using MyOffice.Data.Models.Items;
public interface IItemRepository
{
List<Item> GetAll(Guid userId);
List<Item> GetByCategory(Guid userId, Guid categoryId);
Item? GetByGlobal(Guid userId, Guid globalMotionId);
bool Add(Item item);
bool Update(Item item);
}
@@ -0,0 +1,37 @@
namespace MyOffice.Data.Repositories.Item;
using Microsoft.EntityFrameworkCore;
using MyOffice.Data.Models.Items;
public class ItemCategoryRepository : AppRepository<ItemCategory>, IItemCategoryRepository
{
public List<ItemCategory> GetAll(Guid userId)
{
return _context.ItemCategories
.Include(x => x.Items)
.Where(x => x.UserId == userId)
.ToList();
}
public bool Add(ItemCategory itemCategory)
{
return AddBase(itemCategory) > 0;
}
public ItemCategory? Get(Guid userId, Guid id)
{
return _context.ItemCategories
.Include(x => x.Items)
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
}
public bool Update(ItemCategory itemCategory)
{
return UpdateBase(itemCategory) > 0;
}
public bool Remove(ItemCategory itemCategory)
{
return RemoveBase(itemCategory) > 0;
}
}
@@ -0,0 +1,21 @@
namespace MyOffice.Data.Repositories.Item;
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;
}
}
@@ -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;
}
}