コード例 #1
0
        public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep = new QuestionsDependencies();
            //var ctx = new QuestionsWriteContext();
            var replies = await _dbContext.Replies.ToListAsync();

            //var ctx = new QuestionsWriteContext(replies);
            _dbContext.Replies.AttachRange(replies);
            var ctx = new QuestionsWriteContext(new EFList <Reply>(_dbContext.Replies));

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

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

            _dbContext.Replies.Add(new DatabaseModel.Models.Reply {
                Body = cmd.Body, AuthorUserId = 1, QuestionId = cmd.QuestionId, ReplyId = 8
            });
            //var reply = await _dbContext.Replies.Where(r => r.ReplyId == 2).SingleOrDefaultAsync();
            //reply.Body = "Text updated";
            //_dbContext.Replies.Update(reply);
            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       succ => (IActionResult)Ok("Succeeded"),
                       fail => BadRequest("Reply could not be added")
                       ));
        }
コード例 #2
0
        public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep     = new QuestionsDependencies();
            var replies = await _dbContext.Replies.ToListAsync();

            var ctx = new QuestionsWriteContext(replies);

            var expr = from createTenantResult in QuestionsContext.CreateReply(cmd)
                       select createTenantResult;

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

            _dbContext.Replies.Add(new DatabaseModel.Models.Reply {
                Body = cmd.Body, AuthorUserId = new Guid("9431a4d2-ce83-4ae6-ac13-2f0b2b1d31de"), QuestionId = cmd.QuestionId, ReplyId = 4
            });
            //var reply = await _dbContext.Replies.Where(r => r.ReplyId == 4).SingleOrDefaultAsync();
            //reply.Body = "Text updated";
            //_dbContext.Replies.Update(reply);
            await _dbContext.SaveChangesAsync();


            return(r.Match(
                       succ => (IActionResult)Ok(succ.Body),
                       fail => BadRequest("Reply could not be added")
                       ));
        }
コード例 #3
0
        public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep = new QuestionsDependencies();
            var ctx = new QuestionsWriteContext();

            var expr = from createTenantResult in QuestionsContext.CreateReply(cmd)
                       select createTenantResult;

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

            return(r.Match(
                       succ => (IActionResult)Ok(succ.Body),
                       fail => BadRequest("Reply could not be added")
                       ));
        }
コード例 #4
0
        public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep     = new QuestionsDependencies();
            var replies = await _dbContext.Replies.ToListAsync();

            var ctx = new QuestionsWriteContext(replies);

            var expr = from createReplyResult in QuestionsContext.CreateReply(cmd)
                       select createReplyResult;

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

            _dbContext.Replies.Add(new DatabaseModel.Models.Reply {
                Body = cmd.Body, AuthorUserId = new Guid("f505c32f-3573-4459-8112-af8276d3e919"), QuestionId = cmd.QuestionId, ReplyId = 4
            });
            await _dbContext.SaveChangesAsync();


            return(r.Match(
                       succ => (IActionResult)Ok(succ.Body),
                       fail => BadRequest("Reply could not be added")
                       ));
        }