2022-03-18 22:55:48 +04:00
|
|
|
|
using CoreDatabase;
|
|
|
|
|
using CoreDatabase.Models.Security;
|
2021-04-01 21:30:29 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2022-03-19 19:58:10 +04:00
|
|
|
|
using SecurityContract.BindingModels;
|
2022-03-19 22:48:13 +04:00
|
|
|
|
using SecurityContract.Services.IGenericEntityService;
|
2022-03-19 19:58:10 +04:00
|
|
|
|
using SecurityContract.ViewModels;
|
2021-04-01 21:30:29 +04:00
|
|
|
|
using System.Linq;
|
2022-03-19 19:58:10 +04:00
|
|
|
|
using ToolsModule.Models;
|
2021-04-01 21:30:29 +04:00
|
|
|
|
|
2022-03-19 22:48:13 +04:00
|
|
|
|
namespace SecurityDatabaseImplementation.Implementations.AbstractGenerticEntityService
|
2021-04-01 21:30:29 +04:00
|
|
|
|
{
|
2022-03-19 19:58:10 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Реализация IUserRoleService
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class UserRoleService :
|
2021-04-05 10:08:49 +04:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|