47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| // ***********************************************************************
 | |
| // <copyright file="UserMapper.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="UserRequest"/>,
 | |
|     /// and <see cref="UserAdapter"/>
 | |
|     /// </summary>
 | |
|     public static class UserMapper
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// Maps the UserRequest to UserAdapter.
 | |
|         /// </summary>
 | |
|         /// <param name="newUser">The User to be mapped.</param>
 | |
|         /// <returns>A <see cref="UserAdapter"/> representing
 | |
|         /// the asynchronous execution of the service.</returns>
 | |
|         public static UserAdapter ToAdapter(this UserRequest newUser, IHttpContextAccessor httpContextAccessor)
 | |
|         {
 | |
|             return new UserAdapter
 | |
|             {
 | |
|                 Id = ObjectId.GenerateNewId().ToString(),
 | |
|                 Guid = Guid.NewGuid().ToString(),
 | |
|                 Email = newUser.Email,
 | |
|                 Name = newUser.Name,
 | |
|                 MiddleName = newUser.MiddleName,
 | |
|                 LastName = newUser.LastName,
 | |
|                 DisplayName = $"{newUser.Name} {newUser.MiddleName} {newUser.LastName}",
 | |
|                 RoleId = newUser.RoleId,
 | |
|                 Companies = newUser.Companies,
 | |
|                 Projects = newUser.Projects,
 | |
|                 CreatedAt = DateTime.UtcNow,
 | |
|                 CreatedBy = httpContextAccessor.HttpContext?.User?.FindFirst(ClaimTypes.Email)?.Value ?? string.Empty
 | |
|             };
 | |
|         }
 | |
|     }
 | |
| }
 | 
