public async Task <Topic> RequireTopic(PangulDbContext db, UserContext user, string topic) { var existingTopic = await _getTopic.Execute(db, new GetTopic() { UserContext = user, TopicName = topic, IgnoreRowVersion = true }); if (existingTopic != null) { return(existingTopic); } using (var outOfBandContext = db.CreateScope()) { var newTopic = await _createTopic.Execute(outOfBandContext, new CreateTopic() { UserContext = user, TopicName = topic }); await outOfBandContext.SaveChangesAsync(); return(newTopic); } }
public async Task <Question> CreateQuestion(PangulDbContext db, UserContext user, CreateNewQuestion model) { model.UserContext = user; model.TopicRef = await _topicService.RequireTopic(db, user, model.Topic); return(await _createNewQuestion.Execute(db, model)); }
public async Task <Answer> CreateAnswer(PangulDbContext db, UserContext user, string questionId, string answerBody) { return(await _createNewAnswer.Execute(db, new CreateNewAnswer() { UserContext = user, QuestionId = questionId, Body = answerBody, })); }
public Task <AnswerMeta> RequireAnswerMetaForUser(PangulDbContext db, UserContext user, string answerId) { return(_createAnswerMeta.Execute(db, new CreateNewAnswerMeta() { UserContext = user, AnswerId = answerId, SkipIfExisting = true })); }
public Task <QuestionMeta> RequireQuestionMetaForUser(PangulDbContext db, UserContext user, string questionId) { return(_createQuestionMeta.Execute(db, new CreateNewQuestionMeta() { UserContext = user, QuestionId = questionId, SkipIfExisting = true })); }
public IActionResult Create(CreateCommand createCommand) { var result = _createCommandHandler.Execute(createCommand); return(Created($"api/teams/{result.Id}", result)); }