public async Task ExecuteAsync(AnswerQuestionCommand command) { var question = await _aggregateRepository.RetrieveAsync(command.QuestionId); if (question.State.HasAcceptedAnswer) { throw new AnswerAlreadyAcceptedException(question.State.Id); } await question.FireEventAsync( new QuestionAnsweredEvent( command.QuestionId, command.AnswerId, command.UserId, command.Description, command.OccurredAtUtc, DateTime.UtcNow)); await question.SaveAsync(); }
public async Task ExecuteAsync(LikeQuestionCommand command) { var question = await _aggregateRepository.RetrieveAsync(command.QuestionId); if (question.State.UserId == command.UserId) { // TODO: Better Exception throw new Exception(); } if (question.State.LikedUsers.Any(x => x == command.UserId)) { // TODO: Better Exception throw new Exception(); } await question.FireEventAsync(new QuestionLikedEvent(command.QuestionId, command.UserId, command.OccurredAtUtc, DateTime.UtcNow)); await question.SaveAsync(); }
public async Task ExecuteAsync(AcceptAnswerCommand command) { var processedAtUtc = _date.CurrentDateUtc(); var question = await _aggregateRepository.RetrieveAsync(command.QuestionId); if (question.State.UserId != command.UserId) { throw new UserPermissionException(); } if (question.State.HasAcceptedAnswer) { throw new AnswerAlreadyAcceptedException(command.QuestionId); } if (question.State.Answers.All(x => x.AnswerId != command.AnswerId)) { throw new AnswerNotFoundException(); } await question.FireEventAsync(new AnswerAcceptedEvent(command.QuestionId, command.AnswerId, command.OccurredAtUtc, processedAtUtc)); await question.SaveAsync(); }