sanAntonioSeniorGolf/API/Authentication/EventAuthentication.cs

45 lines
1.5 KiB
C#

using API.Authentication.GrantNames;
using API.Authentication.Interfaces;
using API.DTO.Base;
using API.Services;
using DAL.Models;
namespace API.Authentication
{
public class EventAuthentication : IEventAuthentication
{
private readonly GrantService _grantService;
private readonly ILogger<EventAuthentication> _logger;
public EventAuthentication(GrantService grantService, ILogger<EventAuthentication> logger)
{
_grantService = grantService;
_logger = logger;
}
public bool canGetAll(User user)
{
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAll);
}
public bool canGet(Event model, User user)
{
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanGetAny) ||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanGet).Exists(x => x == model.id);
}
public bool canAdd(EventDTO item, User user)
{
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanAdd);
}
public bool canUpdate(Event model, User user)
{
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanUpdateAny) ||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanUpdate).Exists(x => x == model.id);
}
public bool canDelete(Event model, User user)
{
return _grantService.hasGrant(user.permissionId, EventGrantNames.CanDeleteAny) ||
_grantService.getULongValues(user.permissionId, EventGrantNames.CanDelete).Exists(x => x == model.id);
}
}
}