Files
2026-03-17 09:53:09 -05:00

66 lines
1.9 KiB
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LCU.Library.Internal.IncentiveApiModels.Entities;
using LCU.API.Internal.Operations.IncentiveApiLib.Persistence;
using Microsoft.EntityFrameworkCore;
namespace LCU.API.Internal.Operations.IncentiveApiLib.Repositories;
public class RoleMappingRepository : BaseRepository, IRoleMappingRepository
{
public RoleMappingRepository(IApplicationDbContext context) : base(context)
{
}
public async Task<ICollection<RoleMapping>> GetAllRoleMappingsAsync()
{
return await _context.RoleMappings.OrderBy(x => x.BusinessRole).ToListAsync();
}
public async Task<RoleMapping> GetRoleMappingByIdAsync(int id)
{
return await _context.RoleMappings.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task<int> UpdateRoleMapping(RoleMapping roleMapping)
{
_context.RoleMappings.Update(roleMapping);
return roleMapping.Id;
}
public async Task<int> SaveRoleMappingAsync(RoleMapping roleMapping)
{
await _context.RoleMappings.AddAsync(roleMapping);
return roleMapping.Id;
}
public async Task SaveRoleMappingRangeAsync(IEnumerable<RoleMapping> roleMappings)
{
await _context.RoleMappings.AddRangeAsync(roleMappings);
}
public async Task SaveNewRoleMappingRangeAsync(IEnumerable<RoleMapping> roleMappings)
{
await _context.RoleMappings.AddRangeAsync(roleMappings);
}
public Role FindMatchingRoleFromBusinessRole(string queryRole)
{
if (string.IsNullOrWhiteSpace(queryRole))
{
return Role.MISSING_ROLE;
}
var returnRole = _context.RoleMappings.Where(x => x.BusinessRole.ToUpper() == queryRole.ToUpper()).FirstOrDefault()
?.ApplicationRole;
if (returnRole == null)
{
returnRole = Role.MISSING_ROLE;
}
return returnRole;
}
}