Пример #1
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")
                       ));
        }
Пример #2
0
        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.")));
        }
Пример #3
0
        public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep = new QuestionsDependencies();

            var replies = await _dbContext.Replies.ToListAsync();

            _dbContext.Replies.AttachRange(replies);

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

            var expr = from createTenantResult in QuestionsContextOp.CreateReply(cmd)
                       from checkLanguageResult in QuestionsContextOp.CheckLanguage(new CheckLanguageOpCmd(cmd.Body))
                       from sendAckAuthor in QuestionsContextOp.SendReplyAuthorAcknowledgement(new SendReplyAuthorAcknowledgementCmd(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 = 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")
                       ));
        }
Пример #4
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")
                       ));
        }
Пример #5
0
        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())
                       ));
        }
Пример #7
0
        public async Task <IActionResult> CreateReplyAndAcknowledgement([FromBody] CreateReplyCmd createReplyCmd)
        {
            var expr = from createReplyResult in QuestionsDomain.CreateReply(createReplyCmd.QuestionId, createReplyCmd.AuthorUserId, createReplyCmd.QuestionOwnerId, createReplyCmd.Body)
                       let reply = createReplyResult.SafeCast <ReplyCreated>().Select(r => r)
                                   from checkLanguageResult in QuestionsDomain.CheckLanguage(createReplyCmd.Body)
                                   from sendQuestionOwnerAcknowledgementResult in QuestionsDomain.SendQuestionOwnerAcknowledgement(createReplyCmd.QuestionId, createReplyCmd.QuestionOwnerId)
                                   from sendReplyAuthorAcknowledgementResult in QuestionsDomain.SendReplyAuthorAcknowledgement(createReplyCmd.AuthorUserId, createReplyCmd.QuestionOwnerId, reply)
                                   select new { createReplyResult, checkLanguageResult, sendQuestionOwnerAcknowledgementResult, sendReplyAuthorAcknowledgementResult };

            var ctx = new QuestionReadContext(new List <Post>());
            var r   = await _interpreter.Interpret(expr, ctx);

            await _dbContext.SaveChangesAsync();

            return(r.createReplyResult.Match(
                       created => (IActionResult)Ok("Reply added"),
                       notCreated => BadRequest("Reply not added"),
                       whenInvalidRequest => BadRequest("Invalid request")));
        }
Пример #8
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")
                       ));
        }
 public InvalidRequest(string validationErrors, CreateReplyCmd cmd)
 {
     ValidationErrors = validationErrors;
     Cmd = cmd;
 }
Пример #10
0
 public static Port <ICreateReplyResult> CreateReply(CreateReplyCmd createReplyCmd) =>
 NewPort <CreateReplyCmd, ICreateReplyResult>(createReplyCmd);