示例#1
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionsCmd cmd)
        {
            var dep = new QuestionsDependencies();

            var questions = await _dbContext.Questions.ToListAsync();

            //var ctx = new QuestionsWriteContext(questions);
            _dbContext.Questions.AttachRange(questions);

            var ctx = new QuestionsWriteContext(new EFList <Question>(_dbContext.Questions));

            var expr = from createQuestionResult in QuestionsContext.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       from checkLanguageResult in QuestionsContext.CheckLanguage(new CheckLanguageCmd(cmd.Description))
                       from sendAckAuthor in QuestionsContext.SendQuestionAuthorAcknowledgement(new SendQuestionAuthorAcknowledgementCmd(Guid.NewGuid(), 1, 2))
                       select createQuestionResult;

            var r = await _interpreter.Interpret(expr, ctx, dep);

            _dbContext.Questions.Add(new DatabaseModel.Models.Question {
                QuestionId = cmd.QuestionId, Title = cmd.Title, Description = cmd.Description, Tags = cmd.Tags
            });
            await _dbContext.SaveChangesAsync();

            var reply = await _dbContext.Questions.Where(r => r.QuestionId == cmd.QuestionId).SingleOrDefaultAsync();

            _dbContext.Questions.Update(reply);

            return(r.Match(
                       succ => (IActionResult)Ok("Succeeded"),
                       fail => BadRequest("Question could not be added")
                       ));
        }
示例#2
0
 public static Port <ICreateQuestionsResult> CreateQuestion(CreateQuestionsCmd createQuestionsCmd) =>
 NewPort <CreateQuestionsCmd, ICreateQuestionsResult>(createQuestionsCmd);