Files
Core.Thalos.DAL.API/Core.Thalos.Domain/Contexts/Onboarding/Mappers/RoleMapper.cs
Sergio Matias Urquin 24efe5612c reeplace cerberos by talos
2025-05-18 19:11:08 -06:00

43 lines
1.5 KiB
C#

// ***********************************************************************
// <copyright file="RoleMapper.cs">
// AgileWebs
// </copyright>
// ***********************************************************************
using Core.Thalos.Adapters;
using Core.Thalos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http;
using MongoDB.Bson;
using System.Security.Claims;
namespace Core.Thalos.Domain.Contexts.Onboarding.Mappers
{
/// <summary>
/// Handles mappings between
/// <see cref="RoleRequest"/>,
/// and <see cref="RoleAdapter"/>
/// </summary>
public static class RoleMapper
{
/// <summary>
/// Maps the RoleRequest to RoleAdapter.
/// </summary>
/// <param name="newRole">The Role to be mapped.</param>
/// <returns>A <see cref="RoleAdapter"/> representing
/// the asynchronous execution of the service.</returns>
public static RoleAdapter ToAdapter(this RoleRequest newRole, IHttpContextAccessor httpContextAccessor)
{
return new RoleAdapter
{
Id = ObjectId.GenerateNewId().ToString(),
Name = newRole.Name,
Description = newRole.Description,
Applications = newRole.Applications,
Modules = newRole.Modules,
Permissions = newRole.Permissions,
CreatedAt = DateTime.UtcNow,
CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty
};
}
}
}