1 | using FinkiChattery.Common.Mediator.Contracs;
|
---|
2 | using FinkiChattery.Common.User;
|
---|
3 | using FinkiChattery.Persistence.UnitOfWork;
|
---|
4 | using System;
|
---|
5 | using System.Threading;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace FinkiChattery.Commands.Questioning
|
---|
9 | {
|
---|
10 | public class DeleteAnswerResponseCommand : ICommand<Guid>
|
---|
11 | {
|
---|
12 | public DeleteAnswerResponseCommand(Guid questionUid, Guid answerUid, Guid answerResponseUid)
|
---|
13 | {
|
---|
14 | QuestionUid = questionUid;
|
---|
15 | AnswerUid = answerUid;
|
---|
16 | AnswerResponseUid = answerResponseUid;
|
---|
17 | }
|
---|
18 |
|
---|
19 | public Guid QuestionUid { get; }
|
---|
20 | public Guid AnswerUid { get; }
|
---|
21 | public Guid AnswerResponseUid { get; }
|
---|
22 | }
|
---|
23 |
|
---|
24 | public class DeleteAnswerResponseHandler : ICommandHandler<DeleteAnswerResponseCommand, Guid>
|
---|
25 | {
|
---|
26 | public DeleteAnswerResponseHandler(IUnitOfWork unitOfWork, ICurrentUser currentUser)
|
---|
27 | {
|
---|
28 | UnitOfWork = unitOfWork;
|
---|
29 | CurrentUser = currentUser;
|
---|
30 | }
|
---|
31 |
|
---|
32 | public IUnitOfWork UnitOfWork { get; }
|
---|
33 | public ICurrentUser CurrentUser { get; }
|
---|
34 |
|
---|
35 | public async Task<Guid> Handle(DeleteAnswerResponseCommand request, CancellationToken cancellationToken)
|
---|
36 | {
|
---|
37 | var answerResponse = await UnitOfWork.AnswerResponses.GetByUidAsync(request.AnswerResponseUid);
|
---|
38 |
|
---|
39 | UnitOfWork.AnswerResponses.Delete(answerResponse);
|
---|
40 |
|
---|
41 | await UnitOfWork.SaveAsync();
|
---|
42 |
|
---|
43 | return answerResponse.Uid;
|
---|
44 | }
|
---|
45 | }
|
---|
46 | }
|
---|