Files
Core.Thalos.DAL.API/Core.Cerberos.Domain/Contexts/Onboarding/Mappers/RoleMapper.cs
Sergio Matias Urquin c34987797a Add project files.
2025-04-29 18:55:44 -06:00

43 lines
1.5 KiB
C#

// ***********************************************************************
// <copyright file="RoleMapper.cs">
// HEATH
// </copyright>
// ***********************************************************************
using Core.Cerberos.Adapters;
using Core.Cerberos.Domain.Contexts.Onboarding.Request;
using Microsoft.AspNetCore.Http;
using MongoDB.Bson;
using System.Security.Claims;
namespace Core.Cerberos.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
};
}
}
}