public async Task AskQuestion(Question question, CancellationToken cancellationToken) { var currentUserId = _requestUserProvider.GetUserId(); if (string.IsNullOrEmpty(currentUserId)) { throw new Exception("User not found"); } var questions = await _questionGateway.GetAll(cancellationToken); if (questions.Any(t => t.Title == question.Title)) { throw new Exception("Title already exist!"); } try { question.DateCreated = DateTime.Now; question.LastModified = DateTime.Now; question.AuthorId = currentUserId; await _questionGateway.Add(question, cancellationToken); } catch (Exception e) { Console.WriteLine(e); throw; } }
public AskQuestionCommandBuilder WithQuestionCreated(Question question) { _questionGateway.Add(question, Arg.Any <CancellationToken>()); return(this); }