source: src/FinkiChattery/FinkiChattery.Commands/Questioning/DeleteAnswerResponse/DeleteAnswerResponseCommand.cs@ e071d30

dev
Last change on this file since e071d30 was 6165fd0, checked in by Стојков Марко <mst@…>, 3 years ago

Delete answer and answer response

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[6165fd0]1using FinkiChattery.Common.Mediator.Contracs;
2using FinkiChattery.Common.User;
3using FinkiChattery.Persistence.UnitOfWork;
4using System;
5using System.Threading;
6using System.Threading.Tasks;
7
8namespace 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}
Note: See TracBrowser for help on using the repository browser.