//varianta buna dar nu imi merge MatchAsync si Match
 public async Task OnNextAsync(CreateQuestionResult.ICreateQuestionResult item, StreamSequenceToken token = null)
 {    /*
       * //varianta 1
       * await item.MatchAsync(async created =>
       * {
       *  _posts = await _dbContext.Post.ToListAsync();
       *  return created;
       * }, async notCreated =>
       * {
       *  return notCreated;
       *
       * });
       *
       * //varianta 2
       * item.Match( created =>
       * {
       *  _isDirty = true;
       *  return created;
       * },  notCreated =>
       * {
       *  return notCreated;
       *
       * });
       */
 }
        // public async Task<IActionResult> CreateTenantAsyncAndInviteAdmin([FromBody] CreateTenantCmd createTenantCmd)
        public async Task <IActionResult> CreateQuestionAsync(int questionId, [FromBody] CreateQuestionCmd createQuestionCmd)
        {
            //data
            CreateQuestionWriteContext ctx = new CreateQuestionWriteContext(

                new EFList <Tenant>(_dbContext.Tenant),
                new EFList <TenantUser>(_dbContext.TenantUser),
                new EFList <User>(_dbContext.User),
                new EFList <Post>(_dbContext.Post)

                );

            var dependencies = new QuestionDependencies();

            dependencies.GenerateCodeVerificationToken = () => Guid.NewGuid().ToString();
            dependencies.SendVerifyEmail = SendEmail;

            var expr = from createQuestionResult in CreateQuestionDomain.CreateQuestion(createQuestionCmd)
                       // let user = createQuestionResult.SafeCast<CreateQuestionResult.QuestionCreated>().Select(p => p.Author)
                       let verifyCreateQuestionCmd = new VerifyCreateQuestionCmd()
                                                     from questionCreateVerified in QuestionCreateVerified(createQuestionCmd)
                                                     select new { createQuestionResult, VerifyCreateQuestionResult };

            //var expr1 = from questionResult in CreateQuestionDomain.VerifyCreateQuestion(VerifyCreateQuestionCmd)
            /// select questionResult;

            CreateQuestionResult.ICreateQuestionResult result = await _interpreter.Interpret(expr, Unit.Default, new object());

            return(result.Match(created => Ok(created),
                                notCreated => BadRequest(notCreated),
                                InvalidRequest => ValidationProblem()
                                ));
        }
예제 #3
0
        public async Task OnNextAsync(CreateQuestionResult.ICreateQuestionResult item, StreamSequenceToken token = null)
        {
            //varianta 1
            await item.MatchAsync(async created =>
            {
                _posts = await _dbContext.Post.ToListAsync();
                return(created);
            }, async notCreated =>
            {
                return(notCreated);
            });

            //varianta 2
            item.Match(created =>
            {
                _isDirty = true;
                return(created);
            }, notCreated =>
            {
                return(notCreated);
            });
        }
예제 #4
0
 public override Task PostConditions(CreateQuestionCmd op, CreateQuestionResult.ICreateQuestionResult result, QuestionContext state)
 {
     return(Task.CompletedTask);
 }