-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEmailGroupUsersAppService.cs
More file actions
92 lines (80 loc) · 2.92 KB
/
EmailGroupUsersAppService.cs
File metadata and controls
92 lines (80 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.AspNetCore.Authorization;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
namespace Unity.Notifications.EmailGroups
{
[Authorize]
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(EmailGroupUsersAppService), typeof(IEmailGroupUsersAppService))]
public class EmailGroupUsersAppService : ApplicationService, IEmailGroupUsersAppService
{
private readonly IEmailGroupUsersRepository _emailGroupUsersRepository;
public EmailGroupUsersAppService(IEmailGroupUsersRepository emailGroupUsersRepository)
{
_emailGroupUsersRepository = emailGroupUsersRepository;
}
public async Task<EmailGroupUsersDto> InsertAsync(EmailGroupUsersDto dto)
{
var newUser = await _emailGroupUsersRepository.InsertAsync(new EmailGroupUser
{
GroupId = dto.GroupId,
UserId = dto.UserId,
});
return new EmailGroupUsersDto
{
Id = newUser.Id,
GroupId = newUser.GroupId,
UserId = newUser.UserId,
};
}
public async Task<bool> DeleteUserAsync(Guid id)
{
try
{
await _emailGroupUsersRepository.DeleteAsync(id);
return true;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Error deleting email group with ID {id}: {ex.Message}");
}
}
public async Task<bool> DeleteUsersByUserIdAsync(Guid id)
{
try
{
await _emailGroupUsersRepository.DeleteAsync(id);
return true;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Error deleting email group with ID {id}: {ex.Message}");
}
}
public async Task<bool> DeleteUsersByGroupIdAsync(Guid id)
{
try
{
await _emailGroupUsersRepository.DeleteAsync(id);
return true;
}
catch (Exception ex)
{
throw new InvalidOperationException($"Error deleting email group with ID {id}: {ex.Message}");
}
}
public async Task<List<EmailGroupUsersDto>> GetEmailGroupUsersByGroupIdAsync(Guid id)
{
var users = await _emailGroupUsersRepository.GetListAsync(u => u.GroupId == id);
return ObjectMapper.Map<List<EmailGroupUser>, List<EmailGroupUsersDto>>(users);
}
public async Task<List<EmailGroupUsersDto>> GetListAsync()
{
var users = await _emailGroupUsersRepository.GetListAsync();
return ObjectMapper.Map<List<EmailGroupUser>, List<EmailGroupUsersDto>>(users);
}
}
}