TripMapper.cs
1,613 bytes
| 1 | using App.BLL.DTO; |
|---|---|
| 2 | using App.DTO.v1; |
| 3 | |
| 4 | namespace App.DTO.Mappers; |
| 5 | |
| 6 | public static class TripMapper |
| 7 | { |
| 8 | public static TripDto MapToDto(TripBllDto trip, bool includeParticipants = false) |
| 9 | { |
| 10 | var dto = new TripDto |
| 11 | { |
| 12 | Id = trip.Id, |
| 13 | Name = trip.Name, |
| 14 | Description = trip.Description, |
| 15 | Destination = trip.Destination, |
| 16 | StartDate = trip.StartDate, |
| 17 | EndDate = trip.EndDate, |
| 18 | Status = trip.Status.ToString(), |
| 19 | DefaultCurrencyId = trip.DefaultCurrencyId, |
| 20 | DefaultCurrencyCode = trip.DefaultCurrency?.Code, |
| 21 | DefaultCurrencySymbol = trip.DefaultCurrency?.Symbol, |
| 22 | CreatedById = trip.CreatedById, |
| 23 | ParticipantCount = trip.Participants?.Count(p => p.IsActive) ?? 0 |
| 24 | }; |
| 25 | |
| 26 | if (includeParticipants && trip.Participants != null) |
| 27 | { |
| 28 | dto.Participants = trip.Participants |
| 29 | .Where(p => p.IsActive) |
| 30 | .Select(MapParticipantToDto) |
| 31 | .ToList(); |
| 32 | } |
| 33 | |
| 34 | return dto; |
| 35 | } |
| 36 | |
| 37 | public static TripParticipantDto MapParticipantToDto(TripParticipantBllDto tp) |
| 38 | { |
| 39 | return new TripParticipantDto |
| 40 | { |
| 41 | Id = tp.Id, |
| 42 | TripId = tp.TripId, |
| 43 | UserId = tp.UserId, |
| 44 | UserName = tp.User != null ? $"{tp.User.FirstName} {tp.User.LastName}".Trim() : null, |
| 45 | UserEmail = tp.User?.Email, |
| 46 | Role = tp.Role.ToString(), |
| 47 | Nickname = tp.Nickname, |
| 48 | JoinedAt = tp.JoinedAt, |
| 49 | IsActive = tp.IsActive |
| 50 | }; |
| 51 | } |
| 52 | } |
| 53 | |