fix
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
using MyOffice.Data.Repositories;
|
||||
|
||||
public class AccountAccessRepository : AppRepository<AccountAccess>, IAccountAccessRepository
|
||||
{
|
||||
|
||||
public bool Update(AccountAccess accountAccess)
|
||||
{
|
||||
return UpdateBase(accountAccess) > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Models.Accounts;
|
||||
using MyOffice.Data.Models.Currencies;
|
||||
using MyOffice.Data.Repositories;
|
||||
|
||||
public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
@@ -16,6 +14,7 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.Include(x => x.Motions)!
|
||||
.Where(x => x.AccessRights!.Any(a => a.UserId == userId))
|
||||
.ToList();
|
||||
}
|
||||
@@ -28,6 +27,7 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.Include(x => x.Motions)!
|
||||
.Where(x => x.Categories!.Any(c => c.CategoryId == categoryId) && x.AccessRights!.Any(a => a.UserId == userId))
|
||||
.ToList();
|
||||
}
|
||||
@@ -73,6 +73,11 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
return AddBase(account) > 0;
|
||||
}
|
||||
|
||||
public bool Delete(Account account)
|
||||
{
|
||||
return RemoveBase(account) > 0;
|
||||
}
|
||||
|
||||
public Account? Get(Guid userId, Guid id)
|
||||
{
|
||||
return _context.Accounts!
|
||||
@@ -80,6 +85,7 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
.ThenInclude(x => x.Category)
|
||||
.Include(x => x.AccessRights)!
|
||||
.ThenInclude(x => x.User)
|
||||
.Include(x => x.Motions)!
|
||||
.FirstOrDefault(x => x.Id == id && x.AccessRights!.Any(r => r.UserId == userId));
|
||||
}
|
||||
|
||||
@@ -141,27 +147,42 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
|
||||
|
||||
public List<AccountSimple> GetRestAtDate(Guid userId, DateTime date)
|
||||
{
|
||||
return _context.Accounts
|
||||
.Include(x => x.CurrencyGlobal!)
|
||||
return _context.AccountAccesses!
|
||||
.Where(x => x.UserId == userId)
|
||||
.Include(x => x.Account!)
|
||||
.ThenInclude(x => x.CurrencyGlobal!)
|
||||
.ThenInclude(x => x.Currencies!)
|
||||
.ThenInclude(x => x.CurrentRate!)
|
||||
.Where(x => x.AccessRights!.Any(u => u.UserId == userId))
|
||||
.Select(x => new {
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Currency = x.CurrencyGlobal!.Currencies!.FirstOrDefault(x => x.UserId == userId),
|
||||
Rest = x.Motions!.Sum(m => (m.AmountPlus - m.AmountMinus))
|
||||
.Include(x => x.Account)
|
||||
.ThenInclude(x => x!.Motions)
|
||||
.Select(x => new
|
||||
{
|
||||
Id = x.AccountId,
|
||||
Name = x.Account!.Name,
|
||||
Type = x.Type,
|
||||
Currency = x.Account!.CurrencyGlobal!.Currencies!.FirstOrDefault(c => c.UserId == userId),
|
||||
CurrentRate = x.Account!.CurrencyGlobal!.Currencies!.FirstOrDefault(c => c.UserId == userId)!.CurrentRate,
|
||||
Plus = x.Account.Motions!
|
||||
.Where(x => !x.DeletedOn.HasValue)
|
||||
.Sum(m => m.AmountPlus),
|
||||
Minus = x.Account.Motions!
|
||||
.Where(x => !x.DeletedOn.HasValue)
|
||||
.Sum(m => m.AmountMinus),
|
||||
})
|
||||
.ToList()
|
||||
.Select(x => new AccountSimple
|
||||
{
|
||||
Id = x.Id,
|
||||
Name = x.Name,
|
||||
Balance = x.Rest,
|
||||
CurrencyName = x.Currency?.Name,
|
||||
CurrencyShortName = x.Currency?.ShortName,
|
||||
CurrencyRate = x.Currency?.CurrentRate?.Rate,
|
||||
CurrencyQuantity = x.Currency?.CurrentRate?.Quantity,
|
||||
}).ToList();
|
||||
Type = x.Type,
|
||||
CurrencyName = x.Currency!.Name,
|
||||
CurrencyShortName = x.Currency!.ShortName,
|
||||
CurrencyRate = x.CurrentRate?.Rate,
|
||||
CurrencyQuantity = x.CurrentRate?.Quantity,
|
||||
TotalMinus = x.Minus,
|
||||
TotalPlus = x.Plus,
|
||||
Balance = x.Plus - x.Minus,
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MyOffice.Data.Repositories.Account;
|
||||
|
||||
using Models.Accounts;
|
||||
|
||||
public interface IAccountAccessRepository
|
||||
{
|
||||
bool Update(AccountAccess accountAccess);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public interface IAccountRepository
|
||||
List<AccountDetailed> GetByCategoryDetailed(Guid userId, Guid categoryId);
|
||||
AccountDetailed? GetByIdDetailed(Guid userId, Guid id);
|
||||
bool Add(Account account);
|
||||
bool Delete(Account account);
|
||||
Account? Get(Guid userId, Guid id);
|
||||
bool Update(Account account);
|
||||
bool Remove(Account account);
|
||||
|
||||
@@ -11,7 +11,7 @@ public class ItemRepository : AppRepository<Item>, IItemRepository
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.ItemGlobal)
|
||||
.Where(x => x.Category.UserId == userId)
|
||||
.Where(x => x.Category!.UserId == userId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class ItemRepository : AppRepository<Item>, IItemRepository
|
||||
.Include(x => x.Motions)
|
||||
.Include(x => x.Category)
|
||||
.Include(x => x.ItemGlobal)
|
||||
.Where(x => x.Category.UserId == userId && x.CategoryId == categoryId)
|
||||
.Where(x => x.Category!.UserId == userId && x.CategoryId == categoryId)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class ItemRepository : AppRepository<Item>, IItemRepository
|
||||
.Items
|
||||
.Include(x => x.ItemGlobal)
|
||||
.Where(x => x.Category!.UserId == userId && x.ItemGlobal.Name.Contains(term))
|
||||
.OrderByDescending(x => x.Motions.Count())
|
||||
.OrderByDescending(x => x!.Motions!.Count())
|
||||
.Take(limit)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ public class RepositoryBase<TEntity> where TEntity : class
|
||||
return await _context.Set<TEntity>().FindAsync(id);
|
||||
}
|
||||
|
||||
protected TEntity? GetBase(Guid id)
|
||||
{
|
||||
return _context.Set<TEntity>().Find(id);
|
||||
}
|
||||
|
||||
protected async Task<int> AddBaseAsync(TEntity entity)
|
||||
{
|
||||
//await _context.Set<TEntity>().AddAsync(entity);
|
||||
|
||||
@@ -5,6 +5,7 @@ using MyOffice.Data.Models.Users;
|
||||
public interface IUserRepository
|
||||
{
|
||||
Task<User?> GetUserAsync(Guid id);
|
||||
User? GetUser(Guid id);
|
||||
|
||||
Task<User?> GetByUserUserNameAsync(string userName);
|
||||
User? GetByUserUserName(string userName);
|
||||
|
||||
@@ -11,6 +11,11 @@ public class UserRepository : AppRepository<User>, IUserRepository
|
||||
return await GetBaseAsync(id);
|
||||
}
|
||||
|
||||
public User? GetUser(Guid id)
|
||||
{
|
||||
return GetBase(id);
|
||||
}
|
||||
|
||||
public async Task<User?> GetByUserUserNameAsync(string userName)
|
||||
{
|
||||
return await _context.Users.FirstOrDefaultAsync(x => x.UserName == userName);
|
||||
|
||||
Reference in New Issue
Block a user