Working on organization unit table
This commit is contained in:
@ -78,17 +78,11 @@ namespace UserService.DatabaseLayer.DataModels
|
||||
[Column, Nullable] public int? ParentId { get; set; } // int(11)
|
||||
[Column, Nullable] public int? ManagerId { get; set; } // int(11)
|
||||
[Column, Nullable] public string? EMail { get; set; } // text
|
||||
[Column, NotNull ] public bool IsActive { get; set; } // bit(1)
|
||||
[Column, NotNull ] public string Discriminator { get; set; } = null!; // text
|
||||
[Column, Nullable] public bool? IsActive { get; set; } // bit(1)
|
||||
[Column, NotNull ] public string Discriminator { get; set; } = null!; // varchar(16)
|
||||
|
||||
#region Associations
|
||||
|
||||
/// <summary>
|
||||
/// NodeModels_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="ManagerId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<NodeModel> Ibfks { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// IsMemberOf_ibfk_2_BackReference
|
||||
/// </summary>
|
||||
@ -101,24 +95,6 @@ namespace UserService.DatabaseLayer.DataModels
|
||||
[Association(ThisKey="Id", OtherKey="NodeId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<IsMemberOf> IsMemberOfibfks { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// NodeModels_ibfk_2
|
||||
/// </summary>
|
||||
[Association(ThisKey="ManagerId", OtherKey="Id", CanBeNull=true, Relationship=Relationship.ManyToOne, KeyName="NodeModels_ibfk_2", BackReferenceName="Ibfks")]
|
||||
public NodeModel? Manager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// NodeModels_ibfk_3_BackReference
|
||||
/// </summary>
|
||||
[Association(ThisKey="Id", OtherKey="ParentId", CanBeNull=true, Relationship=Relationship.OneToMany, IsBackReference=true)]
|
||||
public IEnumerable<NodeModel> NodeModelsIbfk3BackReferences { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// NodeModels_ibfk_3
|
||||
/// </summary>
|
||||
[Association(ThisKey="ParentId", OtherKey="Id", CanBeNull=true, Relationship=Relationship.ManyToOne, KeyName="NodeModels_ibfk_3", BackReferenceName="NodeModelsIbfk3BackReferences")]
|
||||
public NodeModel? Parent { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
{
|
||||
Task<IReadOnlyList<T>> GetAllAsync(Expression<Func<NodeModel, bool>>? predicate = null, CancellationToken token = default);
|
||||
Task<T?> GetAsync(Expression<Func<NodeModel, bool>> predicate, CancellationToken token = default);
|
||||
Task AddAsync(T entity, CancellationToken token = default);
|
||||
Task<int> AddAsync(T entity, CancellationToken token = default);
|
||||
Task<bool> UpdateAsync(T entity, CancellationToken token = default);
|
||||
Task DeleteAsync(T entity, CancellationToken token = default);
|
||||
}
|
||||
|
@ -1,38 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using LinqToDB;
|
||||
using UserService.DatabaseLayer.DataModels;
|
||||
using UserService.Infrastructure.DataModels;
|
||||
|
||||
namespace UserService.DatabaseLayer.Repositories
|
||||
{
|
||||
public class OrganizationUnitsRepository : IOrganizationUnitsRepository
|
||||
public class OrganizationUnitsRepository : BaseRepository, IOrganizationUnitsRepository
|
||||
{
|
||||
public Task<IReadOnlyList<OrganizationUnit>> GetAllAsync(Expression<Func<NodeModel, bool>>? predicate = null, CancellationToken token = default)
|
||||
public async Task<IReadOnlyList<OrganizationUnit>> GetAllAsync(Expression<Func<NodeModel, bool>>? predicate = null, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
await using var db = new UserService2DB();
|
||||
var organizationUnits = await db.NodeModels
|
||||
.Where(x => x.Discriminator == nameof(OrganizationUnit))
|
||||
.WhereOrDefault(predicate)
|
||||
.Select(x => new OrganizationUnit
|
||||
{
|
||||
Id = x.Id,
|
||||
CommonName = x.CommonName,
|
||||
Description = x.Description,
|
||||
ParentId = x.ParentId,
|
||||
})
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
return organizationUnits;
|
||||
}
|
||||
|
||||
public Task<OrganizationUnit?> GetAsync(Expression<Func<NodeModel, bool>> predicate, CancellationToken token = default)
|
||||
public async Task<OrganizationUnit?> GetAsync(Expression<Func<NodeModel, bool>> predicate, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
await using var db = new UserService2DB();
|
||||
var result = await db.NodeModels
|
||||
.Where(predicate)
|
||||
.Select(x => new OrganizationUnit
|
||||
{
|
||||
Id = x.Id,
|
||||
CommonName = x.CommonName,
|
||||
Description = x.Description,
|
||||
ParentId = x.ParentId,
|
||||
ManagerId = x.ManagerId,
|
||||
}).FirstOrDefaultAsync(token).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task AddAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
public async Task<int> AddAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (entity == null) throw new ArgumentNullException(nameof(entity));
|
||||
await using var db = new UserService2DB();
|
||||
|
||||
var managerId = entity.Manager?.Id;
|
||||
return await db.NodeModels.InsertWithInt32IdentityAsync(() => new NodeModel
|
||||
{
|
||||
CommonName = entity.CommonName,
|
||||
Description = entity.Description,
|
||||
Discriminator = nameof(OrganizationUnit),
|
||||
ParentId = entity.ParentId,
|
||||
ManagerId = managerId,
|
||||
}, token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
public async Task<bool> UpdateAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
if (entity == null) throw new ArgumentNullException(nameof(entity));
|
||||
await using var db = new UserService2DB();
|
||||
var managerId = entity.Manager?.Id;
|
||||
var changedRows = await db.NodeModels.UpdateAsync(x => new NodeModel
|
||||
{
|
||||
Id = entity.Id,
|
||||
CommonName = entity.CommonName,
|
||||
Description = entity.Description,
|
||||
Discriminator = nameof(OrganizationUnit),
|
||||
ParentId = entity.ParentId,
|
||||
ManagerId = managerId,
|
||||
}, token).ConfigureAwait(false);
|
||||
return changedRows > 0;
|
||||
}
|
||||
|
||||
public Task DeleteAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
public async Task DeleteAsync(OrganizationUnit entity, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
await using var db = new UserService2DB();
|
||||
await db.NodeModels.DeleteAsync(x => x.Id == entity.Id, token).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Task AddAsync(SecurityGroup entity, CancellationToken token = default)
|
||||
public Task<int> AddAsync(SecurityGroup entity, CancellationToken token = default)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
{
|
||||
await using var db = new UserService2DB();
|
||||
var users = await db.NodeModels
|
||||
.LoadWith(x=> x.Parent)
|
||||
.LoadWith(x => x.Parent)
|
||||
.Where(x => x.Discriminator == nameof(User))
|
||||
.WhereOrDefault(predicate)
|
||||
.Select(x => new User
|
||||
@ -28,8 +28,8 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
Description = x.Description,
|
||||
FirstName = x.FirstName,
|
||||
LastName = x.LastName,
|
||||
IsActive = x.IsActive,
|
||||
EMail = x.EMail,
|
||||
IsActive = x.IsActive ?? false,
|
||||
EMail = x.EMail,
|
||||
ParentId = x.ParentId,
|
||||
})
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
@ -37,7 +37,8 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<User?> GetAsync(Expression<Func<NodeModel, bool>> predicate, CancellationToken token = default)
|
||||
public async Task<User?> GetAsync(Expression<Func<NodeModel, bool>> predicate,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
await using var db = new UserService2DB();
|
||||
var result = await db.NodeModels
|
||||
@ -49,18 +50,18 @@ namespace UserService.DatabaseLayer.Repositories
|
||||
Description = x.Description,
|
||||
FirstName = x.FirstName,
|
||||
LastName = x.LastName,
|
||||
IsActive = x.IsActive,
|
||||
IsActive = x.IsActive ?? false,
|
||||
EMail = x.EMail
|
||||
}).FirstOrDefaultAsync(token).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task AddAsync(User entity, CancellationToken token = default)
|
||||
public async Task<int> AddAsync(User entity, CancellationToken token = default)
|
||||
{
|
||||
await using var db = new UserService2DB();
|
||||
|
||||
await db.NodeModels.InsertAsync(() => new NodeModel
|
||||
return await db.NodeModels.InsertWithInt32IdentityAsync(() => new NodeModel
|
||||
{
|
||||
CommonName = entity.CommonName,
|
||||
FirstName = entity.FirstName,
|
||||
|
Reference in New Issue
Block a user