public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd) { var dep = new QuestionsDependencies(); var questions = await _dbContext.Questions.ToListAsync(); _dbContext.Questions.AttachRange(questions); var ctx = new QuestionsWriteContextC(new EFList <Question>(_dbContext.Questions)); var expr = from createQuestionResult in QuestionContext.CreateQuestion(cmd) from checkLanguageResult in QuestionContext.CheckLanguage(new CheckLanguageCmd(cmd.Text)) from sendAckOwner in QuestionContext.SendAcknowledgementToQuestionOwner(new SendAcknowledgementToQuestionOwnerCmd(1, 2)) select createQuestionResult; var r = await _interpreter.Interpret(expr, ctx, dep); _dbContext.Questions.Add(new DatabaseModel.Models.Question { QuestionId = Guid.NewGuid(), Titlu = cmd.Titlu, Text = cmd.Text, Tags = cmd.Tags }); await _dbContext.SaveChangesAsync(); return(r.Match( succ => (IActionResult)Ok(succ.Text), notCreated => BadRequest("NotPosted"), invalidRequest => ValidationProblem() )); }
public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd) { var dep = new QuestionsDependencies(); var replies = await _dbContext.Questions.ToListAsync(); _dbContext.Questions.AttachRange(replies); var ctx = new QuestionsWriteContextC(new EFList <Question>(_dbContext.Questions)); var expr = from createTenantResult in QuestionContext.CreateQuestion(cmd) from checkLanguageResult in QuestionContext.CheckLanguage(new CheckLanguageCmd(cmd.Text)) select createTenantResult; var r = await _interpreter.Interpret(expr, ctx, dep); return(r.Match( created => Ok(created), notCreated => BadRequest(notCreated), invalidRequest => ValidationProblem() )); }