public async Task <IActionResult> CreateAndNotifyReply([FromBody] CreateReplyCmd createNotifyCmd) { QuestionWriteContext ctx = new QuestionWriteContext( new EFList <Post>(_dbContext.Post), new EFList <User>(_dbContext.User)); var dependencies = new QuestionDependencies(); dependencies.GenerateConfirmationToken = () => Guid.NewGuid().ToString(); dependencies.SendNotifyEmail = SendNotifyEmail; var expr = from createReplyResult in QuestionDomain.CreateReply(createNotifyCmd) let user = createReplyResult.SafeCast <CreateReplyResult.ReplyCreated>().Select(p => p.Author) let notifyReplyCmd = new NotifyReplyCmd(user) from NotifyReplyResult in QuestionDomain.NotifyReply(notifyReplyCmd) select new { createReplyResult }; var r = await _interpreter.Interpret(expr, ctx, dependencies); _dbContext.Post.Add(new Post { PostTypeId = 2, PostText = createNotifyCmd.Body, PostedBy = new Guid("f505c32f-3573-4459-8112-af8276d3e919"), PostId = createNotifyCmd.QuestionId }); await _dbContext.SaveChangesAsync(); return(r.createReplyResult.Match( created => (IActionResult)Ok(created.Answer.PostId), notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Reply could not be created."),//todo return 500 (), invalidRequest => BadRequest("Invalid request."))); }
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()) )); }