BudgetCategoryBllDtoFactory.cs
1,462 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 BudgetCategoryBllDtoFactory |
| 7 | { |
| 8 | public static BudgetCategoryBllDto Create(BudgetCategory entity, decimal spentAmount = 0) => 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 | Name = entity.Name, |
| 16 | IconName = entity.IconName, |
| 17 | PlannedAmount = entity.PlannedAmount, |
| 18 | DisplayOrder = entity.DisplayOrder, |
| 19 | ExpenseCount = 0, |
| 20 | SpentAmount = spentAmount |
| 21 | }; |
| 22 | |
| 23 | public static List<BudgetCategoryBllDto> CreateList(IEnumerable<BudgetCategory> entities) |
| 24 | => entities.Select(e => Create(e)).ToList(); |
| 25 | |
| 26 | public static List<BudgetCategoryBllDto> CreateList( |
| 27 | IEnumerable<BudgetCategory> entities, |
| 28 | IReadOnlyDictionary<Guid, decimal> spentByCategoryId) |
| 29 | => entities |
| 30 | .Select(e => Create(e, spentByCategoryId.TryGetValue(e.Id, out var s) ? s : 0)) |
| 31 | .ToList(); |
| 32 | |
| 33 | public static BudgetCategory ToEntity(BudgetCategoryBllDto dto) => new() |
| 34 | { |
| 35 | Id = dto.Id, |
| 36 | TripId = dto.TripId, |
| 37 | Name = dto.Name, |
| 38 | IconName = dto.IconName, |
| 39 | PlannedAmount = dto.PlannedAmount, |
| 40 | DisplayOrder = dto.DisplayOrder |
| 41 | }; |
| 42 | } |
| 43 | |