43 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			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
 | |
|             };
 | |
|         }
 | |
|     }
 | |
| }
 | 
