40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| // ***********************************************************************
 | |
| // <copyright file="PermissionMapper.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="PermissionRequest"/>,
 | |
|     /// and <see cref="PermissionAdapter"/>
 | |
|     /// </summary>
 | |
|     public static class PermissionMapper
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// Maps the permissionRequest to PermissionAdapter.
 | |
|         /// </summary>
 | |
|         /// <param name="newPermission">The Permission to be mapped.</param>
 | |
|         /// <returns>A <see cref="PermissionAdapter"/> representing
 | |
|         /// the asynchronous execution of the service.</returns>
 | |
|         public static PermissionAdapter ToAdapter(this PermissionRequest newPermission, IHttpContextAccessor httpContextAccessor)
 | |
|         {
 | |
|             return new PermissionAdapter
 | |
|             {
 | |
|                 Id = ObjectId.GenerateNewId().ToString(),
 | |
|                 Name = newPermission.Name,
 | |
|                 Description = newPermission.Description,
 | |
|                 CreatedAt = DateTime.UtcNow,
 | |
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty,
 | |
|                 AccessLevel = newPermission.AccessLevel
 | |
|             };
 | |
|         }
 | |
|     }
 | |
| }
 | 
