This commit is contained in:
2023-07-31 08:50:05 +03:00
parent cca943f37d
commit c5d9ae7b93
49 changed files with 546 additions and 398 deletions
@@ -18,4 +18,9 @@ public class AccountAccountCategoryRepository : AppRepository<AccountAccountCate
{
return RemoveBase(accountAccountCategory) > 0;
}
public bool Add(AccountAccountCategory accountAccountCategory)
{
return AddBase(accountAccountCategory) > 0;
}
}
@@ -94,7 +94,7 @@ public class AccountRepository : AppRepository<Account>, IAccountRepository
.ThenInclude(x => x.Category)
.Include(x => x.AccessRights)!
.ThenInclude(x => x.User)
.Include(x => x.Motions)!
//.Include(x => x.Motions)!
.FirstOrDefault(x => x.Id == id && x.AccessRights!.Any(r => r.UserId == userId));
}
@@ -6,4 +6,5 @@ public interface IAccountAccountCategoryRepository
{
List<AccountAccountCategory> Get(Guid userId, Guid accountId, Guid categoryId);
bool Remove(AccountAccountCategory accountAccountCategory);
bool Add(AccountAccountCategory accountAccountCategory);
}
+17 -20
View File
@@ -5,6 +5,7 @@ using DbContext;
public class RepositoryBase<TEntity> where TEntity : class
{
//TODO: Rename
protected readonly AppDbContext _context;
protected RepositoryBase(
@@ -49,41 +50,37 @@ public class RepositoryBase<TEntity> where TEntity : class
return _context.Set<TEntity>().Find(id);
}
protected async Task<int> AddBaseAsync(TEntity entity)
{
//await _context.Set<TEntity>().AddAsync(entity);
await _context.AddAsync(entity);
return await SaveChangesAsync();
}
protected int AddBase(TEntity entity)
{
//_context.Set<TEntity>().Add(entity);
_context.Add(entity);
return SaveChanges();
//_context.Add(entity);
_context.Entry(entity).State = EntityState.Added;
var result = SaveChanges();
_context.Entry(entity).State = EntityState.Detached;
return result;
}
protected int RemoveBase(TEntity entity)
{
_context.Set<TEntity>().Remove(entity);
_context.Entry(entity).State = EntityState.Deleted;
return SaveChanges();
}
var result = SaveChanges();
protected async Task<int> UpdateBaseAsync(TEntity entity)
{
_context.Attach(entity);
_context.Entry(entity).State = EntityState.Modified;
return await SaveChangesAsync();
_context.Entry(entity).State = EntityState.Detached;
return result;
}
protected int UpdateBase(TEntity entity)
{
_context.Attach(entity);
//_context.Attach(entity);
_context.Entry(entity).State = EntityState.Modified;
return SaveChanges();
var result = SaveChanges();
_context.Entry(entity).State = EntityState.Detached;
return result;
}
}
@@ -4,9 +4,7 @@ using Models.Users;
public interface IUserExternalRepository
{
Task<int> AddUserExternalAsync(UserExternal external);
int AddUserExternal(UserExternal external);
Task<int> AddUserExternalsAsync(IEnumerable<UserExternal> claims);
Task<List<UserExternal>> GetUserExternalsByUserIdAsync(Guid userId);
@@ -10,6 +10,6 @@ public interface IUserRepository
Task<User?> GetByUserUserNameAsync(string userName);
User? GetByUserUserName(string userName);
Task<int> AddUserAsync(User user);
Task<int> UpdateUserAsync(User user);
int AddUser(User user);
int UpdateUser(User user);
}
@@ -6,11 +6,6 @@ using Microsoft.EntityFrameworkCore;
public class UserExternalRepository : AppRepository<UserExternal>, IUserExternalRepository
{
public async Task<int> AddUserExternalAsync(UserExternal userExternal)
{
return await AddBaseAsync(userExternal);
}
public int AddUserExternal(UserExternal userExternal)
{
return AddBase(userExternal);
@@ -26,13 +26,13 @@ public class UserRepository : AppRepository<User>, IUserRepository
return _context.Users.FirstOrDefault(x => x.UserName == userName);
}
public async Task<int> AddUserAsync(User user)
public int AddUser(User user)
{
return await AddBaseAsync(user);
return AddBase(user);
}
public async Task<int> UpdateUserAsync(User user)
public int UpdateUser(User user)
{
return await UpdateBaseAsync(user);
return UpdateBase(user);
}
}