refactoring
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
|
||||
public class AccountMotionRepository : AppRepository<AccountMotion>, IAccountMotionRepository
|
||||
{
|
||||
public bool Add(AccountMotion accountMotion)
|
||||
{
|
||||
return AddBase(accountMotion) > 0;
|
||||
}
|
||||
|
||||
public List<AccountMotion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
return _context
|
||||
.AccountMotions
|
||||
.Include(x => x.Motion)
|
||||
.ThenInclude(x => x.MotionGlobal)
|
||||
.Where(x => x.AccountId == accountId && x.DateTime >= dateFrom && x.DateTime <= dateTo)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ThenByDescending(x => x.CreatedOn)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountMotionRepository
|
||||
{
|
||||
bool Add(AccountMotion accountMotion);
|
||||
List<AccountMotion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IMotionRepository
|
||||
{
|
||||
bool Add(Motion motion);
|
||||
List<Motion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Accounts;
|
||||
|
||||
public class MotionRepository : AppRepository<Motion>, IMotionRepository
|
||||
{
|
||||
public bool Add(Motion motion)
|
||||
{
|
||||
return AddBase(motion) > 0;
|
||||
}
|
||||
|
||||
public List<Motion> GetByAccount(Guid accountId, DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
return _context
|
||||
.Motions
|
||||
.Include(x => x.Item)
|
||||
.ThenInclude(x => x.ItemGlobal)
|
||||
.Where(x => x.AccountId == accountId && x.DateTime >= dateFrom && x.DateTime <= dateTo)
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ThenByDescending(x => x.CreatedOn)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Models.Motions;
|
||||
|
||||
public interface IMotionCategoryRepository
|
||||
{
|
||||
List<MotionCategory> GetAll(Guid userId);
|
||||
bool Add(MotionCategory accountCategory);
|
||||
MotionCategory? Get(Guid userId, Guid id);
|
||||
bool Update(MotionCategory accountCategory);
|
||||
bool Remove(MotionCategory accountCategory);
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Models.Motions;
|
||||
|
||||
public interface IMotionGlobalRepository
|
||||
{
|
||||
MotionGlobal? Get(Guid id);
|
||||
MotionGlobal? GetByName(string name);
|
||||
bool Add(MotionGlobal motionGlobal);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Models.Motions;
|
||||
|
||||
public interface IMotionRepository
|
||||
{
|
||||
List<MotionAccount> GetAll(Guid userId);
|
||||
List<MotionAccount> GetByCategory(Guid userId, Guid categoryId);
|
||||
|
||||
MotionAccount? GetByGlobal(Guid userId, Guid globalMotionId);
|
||||
bool Add(MotionAccount motionAccount);
|
||||
bool Update(MotionAccount motionAccount);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Motions;
|
||||
|
||||
public class MotionCategoryRepository : AppRepository<MotionCategory>, IMotionCategoryRepository
|
||||
{
|
||||
public List<MotionCategory> GetAll(Guid userId)
|
||||
{
|
||||
return _context.MotionCategories
|
||||
.Include(x => x.Motions)
|
||||
.Where(x => x.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public bool Add(MotionCategory motionCategory)
|
||||
{
|
||||
return AddBase(motionCategory) > 0;
|
||||
}
|
||||
|
||||
public MotionCategory? Get(Guid userId, Guid id)
|
||||
{
|
||||
return _context.MotionCategories
|
||||
.Include(x => x.Motions)
|
||||
.FirstOrDefault(x => x.Id == id && x.UserId == userId);
|
||||
}
|
||||
|
||||
public bool Update(MotionCategory motionCategory)
|
||||
{
|
||||
return UpdateBase(motionCategory) > 0;
|
||||
}
|
||||
|
||||
public bool Remove(MotionCategory motionCategory)
|
||||
{
|
||||
return RemoveBase(motionCategory) > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Models.Motions;
|
||||
|
||||
public class MotionGlobalRepository : AppRepository<MotionGlobal>, IMotionGlobalRepository
|
||||
{
|
||||
public MotionGlobal? Get(Guid id)
|
||||
{
|
||||
return _context.GlobalMotions.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
public MotionGlobal? GetByName(string name)
|
||||
{
|
||||
return _context.GlobalMotions.FirstOrDefault(x => x.Name == name);
|
||||
}
|
||||
|
||||
public bool Add(MotionGlobal motionGlobal)
|
||||
{
|
||||
return AddBase(motionGlobal) > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
namespace MyOffice.Data.Repositories.Motion;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models.Motions;
|
||||
|
||||
public class MotionRepository : AppRepository<MotionAccount>, IMotionRepository
|
||||
{
|
||||
public List<MotionAccount> GetAll(Guid userId)
|
||||
{
|
||||
return _context.Motions
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.MotionGlobal)
|
||||
.Where(x => x.Category.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MotionAccount> GetByCategory(Guid userId, Guid categoryId)
|
||||
{
|
||||
return _context.Motions
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.MotionGlobal)
|
||||
.Where(x => x.Category.UserId == userId && x.CategoryId == categoryId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MotionAccount? GetByGlobal(Guid userId, Guid globalMotionId)
|
||||
{
|
||||
return _context.Motions
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.MotionGlobal)
|
||||
.FirstOrDefault(x => x.Category.UserId == userId && x.MotionGlobalId == globalMotionId);
|
||||
}
|
||||
|
||||
public bool Update(MotionAccount motionAccount)
|
||||
{
|
||||
return base.UpdateBase(motionAccount) > 0;
|
||||
}
|
||||
|
||||
public bool Add(MotionAccount motionAccount)
|
||||
{
|
||||
return base.AddBase(motionAccount) > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user