-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGeneralProfile.cs
More file actions
77 lines (73 loc) · 3.86 KB
/
Copy pathGeneralProfile.cs
File metadata and controls
77 lines (73 loc) · 3.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using TalentManagementAPI.Application.Features.Departments.Commands.CreateDepartment;
using TalentManagementAPI.Application.Features.Employees.Commands.CreateEmployee;
using TalentManagementAPI.Application.Features.Positions.DTOs;
using TalentManagementAPI.Application.Features.SalaryRanges.Commands.CreateSalaryRange;
using TalentManagementAPI.Domain.ValueObjects;
namespace TalentManagementAPI.Application.Mappings
{
// Defines a mapping profile for general mappings between entities and view models.
public class GeneralProfile : IRegister
{
public void Register(TypeAdapterConfig config)
{
// Maps an Employee entity to a GetEmployeesViewModel, and vice versa.
config.NewConfig<Employee, GetEmployeesViewModel>()
.Map(dest => dest.FirstName, src => src.Name.FirstName)
.Map(dest => dest.MiddleName, src => src.Name.MiddleName)
.Map(dest => dest.LastName, src => src.Name.LastName);
config.NewConfig<GetEmployeesViewModel, Employee>()
.Map(dest => dest.Name, src => new PersonName(src.FirstName, src.MiddleName, src.LastName));
// Maps a Position entity to a PositionSummaryDto, and vice versa.
config.NewConfig<Position, PositionSummaryDto>()
.Map(dest => dest.PositionTitle, src => src.PositionTitle.Value);
config.NewConfig<PositionSummaryDto, Position>()
.Map(dest => dest.PositionTitle, src => new PositionTitle(src.PositionTitle));
// Maps a Department entity to a GetDepartmentsViewModel, and vice versa.
config.NewConfig<Department, GetDepartmentsViewModel>()
.Map(dest => dest.Name, src => src.Name.Value);
config.NewConfig<GetDepartmentsViewModel, Department>()
.Map(dest => dest.Name, src => new DepartmentName(src.Name));
// Maps a SalaryRange entity to a GetSalaryRangesViewModel, and vice versa.
config.NewConfig<SalaryRange, GetSalaryRangesViewModel>().TwoWays();
// Maps a CreatePositionCommand to a Position entity.
config.NewConfig<CreatePositionCommand, Position>()
.MapWith(src => new Position
{
PositionTitle = new PositionTitle(src.PositionTitle),
PositionNumber = src.PositionNumber,
PositionDescription = src.PositionDescription,
DepartmentId = src.DepartmentId,
SalaryRangeId = src.SalaryRangeId
});
// Maps a CreateDepartmentCommand to a Department entity.
config.NewConfig<CreateDepartmentCommand, Department>()
.MapWith(src => new Department
{
Name = new DepartmentName(src.Name)
});
// Maps a CreateEmployeeCommand to an Employee entity.
config.NewConfig<CreateEmployeeCommand, Employee>()
.MapWith(src => new Employee
{
Name = new PersonName(src.FirstName, src.MiddleName, src.LastName),
PositionId = src.PositionId,
DepartmentId = src.DepartmentId,
Salary = src.Salary,
Birthday = src.Birthday,
Email = src.Email,
Gender = src.Gender,
EmployeeNumber = src.EmployeeNumber,
Prefix = src.Prefix,
Phone = src.Phone
});
// Maps a CreateSalaryRangeCommand to a SalaryRange entity.
config.NewConfig<CreateSalaryRangeCommand, SalaryRange>()
.MapWith(src => new SalaryRange
{
Name = src.Name,
MinSalary = src.MinSalary,
MaxSalary = src.MaxSalary
});
}
}
}