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> GetAllRoleMappingsAsync() { return await _context.RoleMappings.OrderBy(x => x.BusinessRole).ToListAsync(); } public async Task GetRoleMappingByIdAsync(int id) { return await _context.RoleMappings.FirstOrDefaultAsync(x => x.Id == id); } public async Task UpdateRoleMapping(RoleMapping roleMapping) { _context.RoleMappings.Update(roleMapping); return roleMapping.Id; } public async Task SaveRoleMappingAsync(RoleMapping roleMapping) { await _context.RoleMappings.AddAsync(roleMapping); return roleMapping.Id; } public async Task SaveRoleMappingRangeAsync(IEnumerable roleMappings) { await _context.RoleMappings.AddRangeAsync(roleMappings); } public async Task SaveNewRoleMappingRangeAsync(IEnumerable 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; } }