public async Task <IActionResult> CreateTenantAsyncAndInviteAdmin([FromBody] CreateReplyCmd createReplyCmd) { var expr = from createReplyResult in QuestionDomain.CreateReply(createReplyCmd.QuestionId, createReplyCmd.AuthorQuestionId, createReplyCmd.QuestionOwnerId, createReplyCmd.Body) let reply = createReplyResult.SafeCast <ReplyCreated>().Select(re => re) from checkLanguageResult in QuestionDomain.CheckLanguage(createReplyCmd.Body) from ownerAcknowledgementResult in QuestionDomain.QuestionOwnerAcknowledgement(createReplyCmd.QuestionId, createReplyCmd.QuestionOwnerId) from authorAcknowledgementResult in QuestionDomain.ReplyAuthorAcknowledgement(createReplyCmd.QuestionId, createReplyCmd.AuthorQuestionId, reply) select new { createReplyResult, checkLanguageResult, ownerAcknowledgementResult, authorAcknowledgementResult }; var ctx = new QuestionReadContext(new List <Post>()); var r = await _interpreter.Interpret(expr, ctx); return(r.createReplyResult.Match( created => (IActionResult)Ok("Reply added"), notCreated => BadRequest("Reply not added") )); }
public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd createReplyCmd) { var expr = from createReplyResult in QuestionDomain.CreateReply(createReplyCmd.QuestionId, createReplyCmd.Body) let reply = createReplyResult.SafeCast <ReplyCreated>().Select(r => r) from checkLanguageResult in QuestionDomain.CheckLanguage(createReplyCmd.Body) from questionOwnerAckResult in QuestionDomain.AckQuestionOwner(createReplyCmd.QuestionId, "Some message") //de aici se poate extrage questionOwnerId from replyAuthorAckResult in QuestionDomain.AckReplyAuthor(createReplyCmd.replyId, "some notify message") //de aici se poate extrage replyAuthodId select new { createReplyResult, questionOwnerAckResult, replyAuthorAckResult }; //evenimentele returnate de workflow var ctx = new QuestionReadContext(new List <Post>()); var r = await _interpreter.Interpret(expr, ctx); await _dbContext.SaveChangesAsync(); return(r.createReplyResult.Match( Created => (IActionResult)OK(new Object()), NotCreated => BadRequest(new Object()) )); }
public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd createQuestionCmd) { QuestionWriteContext ctx = new QuestionWriteContext( new EFList <Post>(_dbContext.Post)); var dependencies = new QuestionDependencies(); var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd) // let adminUser = createQuestionResult.SafeCast<CreateQuestionResult.TenantCreated>().Select(p => p.AdminUser) // let inviteAdminCmd = new InviteTenantAdminCmd(adminUser) from checkLanguageResult in QuestionDomain.CheckLanguage(new CheckLanguageCmd(createQuestionCmd.Body)) select new { createQuestionResult, checkLanguageResult }; var r = await _interpreter.Interpret(expr, ctx, dependencies); _dbContext.SaveChanges(); return(r.createQuestionResult.Match( created => (IActionResult)Ok("OK"), notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Tenant could not be created."),//todo return 500 (), invalidRequest => BadRequest("Invalid request."))); }