46 lines
2.1 KiB
C#
46 lines
2.1 KiB
C#
using CoreDatabase;
|
|
using CoreDatabase.Models.Security;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SecurityContract.BindingModels;
|
|
using SecurityContract.Services.IGenericEntityService;
|
|
using SecurityContract.ViewModels;
|
|
using System.Linq;
|
|
using ToolsModule.ManagmentEntity;
|
|
|
|
namespace SecurityDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
|
{
|
|
/// <summary>
|
|
/// Реализация IUserRoleService
|
|
/// </summary>
|
|
public class UserRoleService :
|
|
AbstractGenerticEntityService<UserRoleGetBindingModel, UserRoleSetBindingModel, UserRole, UserRoleListViewModel, UserRoleViewModel>,
|
|
IUserRoleService
|
|
{
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, UserRoleSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, UserRole entity, UserRoleGetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override IQueryable<UserRole> AdditionalCheckingWhenReadingList(IQueryable<UserRole> query, UserRoleGetBindingModel model)
|
|
{
|
|
if (model.RoleId.HasValue)
|
|
{
|
|
query = query.Where(x => x.RoleId == model.RoleId);
|
|
}
|
|
if (model.UserId.HasValue)
|
|
{
|
|
query = query.Where(x => x.UserId == model.UserId);
|
|
}
|
|
return query;
|
|
}
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, UserRoleSetBindingModel model) => OperationResultModel.Success(null);
|
|
|
|
protected override void AdditionalDeleting(DbContext context, UserRole entity, UserRoleGetBindingModel model) { }
|
|
|
|
protected override UserRole GetUniqueEntity(UserRoleSetBindingModel model, DbContext context) => context.Set<UserRole>().FirstOrDefault(x => x.UserId == model.UserId && x.RoleId == model.RoleId && x.Id != model.Id);
|
|
|
|
protected override IQueryable<UserRole> IncludingWhenReading(IQueryable<UserRole> query) => query.Include(x => x.Role).Include(x => x.User);
|
|
|
|
protected override IQueryable<UserRole> OrderingWhenReading(IQueryable<UserRole> query) => query.OrderBy(x => x.User.UserName);
|
|
}
|
|
} |