You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OptifitWebService/Server/Mappers/AlumnisMappers.cs

64 lines
1.8 KiB

using Infrastructure.Entities;
using Server.Dto.Request;
using Server.Dto.Response;
using Shared.Enums;
namespace Server.Mappers;
public static class AlumnisMappers
{
public static ResponseAlumniDto ToDto(this User alumni)
{
return new ResponseAlumniDto
{
Id = alumni.Id,
Email = alumni.Email,
ERole = alumni.Role.ToERole(),
EntryYear = alumni.EntryYear,
FirstName = alumni.FirstName,
LastName = alumni.LastName,
LinkedinUrl = alumni.Linkedin,
GithubUrl = alumni.Github,
PortfolioUrl = alumni.WebSite,
Experiences = alumni.Experiences.Select(e => e.ToDto()),
Formations = alumni.Formations.Select(f => f.ToDto())
};
}
public static ResponseRestrictedAlumniDto ToDtoRestricted(this User alumni)
{
return new ResponseRestrictedAlumniDto
{
Id = alumni.Id,
FirstName = alumni.FirstName,
LastName = alumni.LastName,
LinkedinUrl = alumni.Linkedin
};
}
public static User ToEntity(this RequestAlumniDto alumni)
{
return new User
{
Email = alumni.Email,
Password = alumni.Password,
EntryYear = alumni.EntryYear,
FirstName = alumni.FirstName,
LastName = alumni.LastName,
Linkedin = alumni.LinkedinUrl,
Github = alumni.GithubUrl,
WebSite = alumni.PortfolioUrl,
Role = "USER"
};
}
public static ERole ToERole(this string role)
{
return role switch
{
"ADMIN" => ERole.ADMIN,
"MODERATOR" => ERole.MODERATOR,
"USER" => ERole.USER
};
}
}