profileShare

rasmusjy / splitapp-backend-clean-onion

Read-only snapshot

No repository description.

main default branch 429 files Expires Sep 13, 2026, 9:06 AM
SplitPresetAdminService.cs 1,873 bytes
1 using App.BLL.DTO;
2 using App.BLL.Mappers;
3 using App.Domain.Contracts;
4
5 namespace App.BLL.Services.Admin;
6
7 public class SplitPresetAdminService : ISplitPresetAdminService
8 {
9 private readonly IAppUnitOfWork _uow;
10
11 public SplitPresetAdminService(IAppUnitOfWork uow)
12 {
13 _uow = uow;
14 }
15
16 public async Task<List<SplitPresetBllDto>> GetAllAsync(string? search)
17 {
18 var presets = (await _uow.SplitPresets.GetAllAsync()).ToList();
19 if (!string.IsNullOrEmpty(search))
20 presets = presets.Where(s => s.Name.Contains(search)).ToList();
21 return SplitPresetBllDtoFactory.CreateList(presets.OrderByDescending(s => s.Id), includeMembers: true);
22 }
23
24 public async Task<SplitPresetBllDto?> GetByIdAsync(Guid id)
25 {
26 var entity = await _uow.SplitPresets.GetByIdAsync(id);
27 return entity == null ? null : SplitPresetBllDtoFactory.Create(entity, includeMembers: true);
28 }
29
30 public async Task CreateAsync(SplitPresetBllDto entity)
31 {
32 var domainEntity = SplitPresetBllDtoFactory.ToEntity(entity);
33 domainEntity.Id = Guid.NewGuid();
34 _uow.SplitPresets.Add(domainEntity);
35 await _uow.SaveChangesAsync();
36 }
37
38 public async Task DeleteAsync(Guid id)
39 {
40 await _uow.SplitPresets.RemoveAsync(id);
41 await _uow.SaveChangesAsync();
42 }
43
44 public async Task<List<TripBllDto>> GetTripsAsync()
45 {
46 var trips = await _uow.Trips.GetAllAsync();
47 return TripBllDtoFactory.CreateList(trips.OrderBy(t => t.Name));
48 }
49
50 public async Task<List<AppUserBllDto>> GetUsersAsync()
51 {
52 var users = await _uow.Users.GetAllAsync();
53 return users.Select(u => new AppUserBllDto
54 {
55 Id = u.Id,
56 FirstName = u.FirstName,
57 LastName = u.LastName,
58 Email = u.Email
59 }).ToList();
60 }
61 }
62