profileShare

rasmusjy / splitapp-backend-clean-onion

Read-only snapshot

No repository description.

main default branch 429 files Expires Sep 13, 2026, 9:06 AM
TripAdminService.cs 2,098 bytes
1 using App.BLL.DTO;
2 using App.BLL.Mappers;
3 using App.Domain;
4 using App.Domain.Contracts;
5
6 namespace App.BLL.Services.Admin;
7
8 public class TripAdminService : ITripAdminService
9 {
10 private readonly IAppUnitOfWork _uow;
11
12 public TripAdminService(IAppUnitOfWork uow)
13 {
14 _uow = uow;
15 }
16
17 public async Task<List<TripBllDto>> GetAllAsync(string? search)
18 {
19 var items = (await _uow.Trips.GetAllAsync()).ToList();
20 if (!string.IsNullOrEmpty(search))
21 items = items.Where(t => t.Name.Contains(search)).ToList();
22 return TripBllDtoFactory.CreateList(items.OrderByDescending(t => t.CreatedAt));
23 }
24
25 public async Task<List<CurrencyBllDto>> GetAllCurrenciesAsync()
26 {
27 var currencies = await _uow.GetRepository<Currency>().GetAllAsync();
28 return CurrencyBllDtoFactory.CreateList(currencies);
29 }
30
31 public async Task<TripBllDto?> GetByIdAsync(Guid id)
32 {
33 var trip = await _uow.Trips.GetByIdAsync(id);
34 return trip == null ? null : TripBllDtoFactory.Create(trip);
35 }
36
37 public async Task CreateAsync(TripBllDto entity)
38 {
39 var domainEntity = TripBllDtoFactory.ToEntity(entity);
40 domainEntity.Id = Guid.NewGuid();
41 _uow.Trips.Add(domainEntity);
42 await _uow.SaveChangesAsync();
43 }
44
45 public async Task UpdateAsync(TripBllDto entity)
46 {
47 var existing = await _uow.Trips.GetByIdAsync(entity.Id);
48 if (existing == null) return;
49 existing.Name = entity.Name;
50 existing.Description = entity.Description;
51 existing.Destination = entity.Destination;
52 existing.StartDate = entity.StartDate;
53 existing.EndDate = entity.EndDate;
54 existing.Status = entity.Status;
55 existing.DefaultCurrencyId = entity.DefaultCurrencyId;
56 _uow.Trips.Update(existing);
57 await _uow.SaveChangesAsync();
58 }
59
60 public async Task DeleteAsync(Guid id)
61 {
62 await _uow.Trips.RemoveAsync(id);
63 await _uow.SaveChangesAsync();
64 }
65
66 public Task<bool> ExistsAsync(Guid id) => _uow.Trips.ExistsAsync(id);
67 }
68