2021-04-01 21:30:29 +04:00
|
|
|
|
using DatabaseCore;
|
|
|
|
|
using DatabaseCore.Models.Security;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using ModuleTools.Models;
|
|
|
|
|
using SecurityBusinessLogic.BindingModels;
|
|
|
|
|
using SecurityBusinessLogic.Interfaces;
|
|
|
|
|
using SecurityBusinessLogic.ViewModels;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace SecurityDatabaseImplementation.Implementations
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IUserRoleService
|
|
|
|
|
/// </summary>
|
2021-04-05 10:08:49 +04:00
|
|
|
|
public class UserRoleService :
|
|
|
|
|
AbstractGenerticEntityService<UserRoleGetBindingModel, UserRoleSetBindingModel, UserRole, UserRoleListViewModel, UserRoleViewModel>,
|
|
|
|
|
IUserRoleService
|
2021-04-01 21:30:29 +04:00
|
|
|
|
{
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenAdding(DbContext context, UserRoleSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenDeleting(DbContext context, UserRole entity, UserRoleGetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override IQueryable<UserRole> AdditionalCheckingWhenReadingList(IQueryable<UserRole> query, UserRoleGetBindingModel model)
|
2021-04-01 21:30:29 +04:00
|
|
|
|
{
|
|
|
|
|
if (model.RoleId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.RoleId == model.RoleId);
|
|
|
|
|
}
|
|
|
|
|
if (model.UserId.HasValue)
|
|
|
|
|
{
|
|
|
|
|
query = query.Where(x => x.UserId == model.UserId);
|
|
|
|
|
}
|
2021-04-05 10:08:49 +04:00
|
|
|
|
return query;
|
2021-04-01 21:30:29 +04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
protected override OperationResultModel AdditionalCheckingWhenUpdateing(DbContext context, UserRoleSetBindingModel model) => OperationResultModel.Success(null);
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2021-04-05 12:25:10 +04:00
|
|
|
|
protected override void AdditionalDeleting(DbContext context, UserRole entity, UserRoleGetBindingModel model) { }
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
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);
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2021-04-05 10:08:49 +04:00
|
|
|
|
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);
|
2021-04-01 21:30:29 +04:00
|
|
|
|
}
|
|
|
|
|
}
|