using FlexJobApi.Core;
|
using Furion.DatabaseAccessor;
|
using MediatR;
|
using Microsoft.EntityFrameworkCore;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace FlexJobApi.UserServer.Application
|
{
|
/// <summary>
|
/// 设置菜单切换信息
|
/// </summary>
|
public class SetMenuSwitchCommandHandler(
|
IRepository<Menu> rep
|
) : IRequestHandler<SetMenuSwitchCommand, int>
|
{
|
private readonly IRepository<Menu> rep = rep;
|
|
/// <inheritdoc/>
|
public async Task<int> Handle(SetMenuSwitchCommand request, CancellationToken cancellationToken)
|
{
|
var entities = await rep.AsQueryable()
|
.Where(it => request.Ids.Contains(it.Id))
|
.ToListAsync(cancellationToken);
|
foreach (var entity in entities)
|
{
|
if (request.Type.HasValue)
|
{
|
entity.Type = request.Type.Value;
|
}
|
if (request.IsDisabled.HasValue)
|
{
|
entity.IsDisabled = request.IsDisabled.Value;
|
}
|
if (request.IsCache.HasValue)
|
{
|
entity.IsCache = request.IsCache.Value;
|
}
|
}
|
|
if (entities.Any())
|
{
|
await rep.UpdateAsync(entities);
|
return entities.Count;
|
}
|
|
return 0;
|
}
|
}
|
}
|