WishlistBllDtoFactory.cs
1,850 bytes
| 1 | using SplitApp.Modules.Trips.Domain.Entities; |
|---|---|
| 2 | using SplitApp.WebApp.Application.DTO; |
| 3 | |
| 4 | namespace SplitApp.WebApp.Application.Mappers; |
| 5 | |
| 6 | public static class WishlistBllDtoFactory |
| 7 | { |
| 8 | public static TripWishlistItemBllDto Create(TripWishlistItem entity) => new() |
| 9 | { |
| 10 | Id = entity.Id, |
| 11 | CreatedAt = entity.CreatedAt, |
| 12 | UpdatedAt = entity.UpdatedAt, |
| 13 | TripId = entity.TripId, |
| 14 | Trip = entity.Trip != null ? TripBllDtoFactory.Create(entity.Trip) : null, |
| 15 | AddedByUserId = entity.AddedByUserId, |
| 16 | AddedByUser = AppUserBllDtoFactory.Create(entity.AddedByUser), |
| 17 | Title = entity.Title, |
| 18 | Description = entity.Description, |
| 19 | Category = entity.Category, |
| 20 | Priority = entity.Priority, |
| 21 | EstimatedCost = entity.EstimatedCost, |
| 22 | Url = entity.Url, |
| 23 | Location = entity.Location, |
| 24 | IsCompleted = entity.IsCompleted, |
| 25 | CompletedAt = entity.CompletedAt, |
| 26 | DisplayOrder = entity.DisplayOrder, |
| 27 | VoteCount = entity.Votes?.Count(v => v.IsInterested) ?? 0, |
| 28 | VoterUserIds = entity.Votes?.Where(v => v.IsInterested).Select(v => v.UserId).ToList() ?? new List<Guid>() |
| 29 | }; |
| 30 | |
| 31 | public static List<TripWishlistItemBllDto> CreateList(IEnumerable<TripWishlistItem> entities) |
| 32 | => entities.Select(Create).ToList(); |
| 33 | |
| 34 | public static TripWishlistItem ToEntity(TripWishlistItemBllDto dto) => new() |
| 35 | { |
| 36 | Id = dto.Id, |
| 37 | TripId = dto.TripId, |
| 38 | AddedByUserId = dto.AddedByUserId, |
| 39 | Title = dto.Title, |
| 40 | Description = dto.Description, |
| 41 | Category = dto.Category, |
| 42 | Priority = dto.Priority, |
| 43 | EstimatedCost = dto.EstimatedCost, |
| 44 | Url = dto.Url, |
| 45 | Location = dto.Location, |
| 46 | IsCompleted = dto.IsCompleted, |
| 47 | CompletedAt = dto.CompletedAt, |
| 48 | DisplayOrder = dto.DisplayOrder |
| 49 | }; |
| 50 | } |
| 51 | |