Ejemplo n.º 1
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            var dep       = new QuestionDependencies();
            var questions = await _dbContext.Questions.ToListAsync();

            _dbContext.Questions.AttachRange(questions);
            var ctx = new QuestionWriteContext(new EFList <Questions>(_dbContext.Questions));
            // var ctx = new QuestionWriteContext(questions);

            var expr = from createQuestionResult in QuestionContext.CreateQuestion(cmd)
                       from checkLanguageResult in QuestionContext.CheckLanguage(new CheckLanguageCmd(cmd.Body))
                       select createQuestionResult;

            /* var expr = from createQuestionResult in QuestionContext.CreateQuestion(cmd)
             *          from checkLanguageResult in QuestionContext.CheckLanguage(new CheckLanguageCmd(cmd.Body))
             *          from sendAckToQuestionOwner in QuestionContext.SendAckToQuestionOwner(new SendAckToQuestionOwnerCmd(1, 2))
             *          select createQuestionResult; */

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

            _dbContext.Questions.Add(new DatabaseModel.Models.Questions {
                QuestionId = Guid.NewGuid(), Title = cmd.Title, Body = cmd.Body, Tags = cmd.Tags
            });
            //var question=await _dbContext.Questions.Where(r => r.QuestionId== new Guid("20000000-0000-0000-0000-000000000000")).SingleOrDefaultAsync();

            // _dbContext.Questions.Update(question);
            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       created => (IActionResult)Ok(created.Body),
                       notcreated => BadRequest("NotPosted"),
                       invalidRequest => ValidationProblem()
                       ));
        }
Ejemplo n.º 2
0
            public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
            {
                var dep = new QuestionDependencies();

                var questions = await _dbContext.QuestionModel.ToListAsync();

                var ctx = new QuestionWriteContext(questions);

                var expr = from CreateTenantResult in QuestionDomain.CreateQuestion(cmd)
                           select CreateTenantResult;

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


                _dbContext.QuestionModel.Add(new DatabaseModel.Models.QuestionModel {
                    Title = cmd.Title, Description = cmd.Description, Tags = cmd.Tags
                });
                //var reply = await _dbContext.QuestionModel.Where(r => r.Title == "Intrebarea1").SingleOrDefaultAsync();
                //_dbContext.QuestionModel.Update(reply);
                await _dbContext.SaveChangesAsync();

                return(r.Match(
                           succ => (IActionResult)Ok(succ),
                           fail => BadRequest("Reply could not be added")
                           ));
            }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            var dep = new QuestionDependencies();

            var questions = await _dbContext.QuestionModel.ToListAsync();

            // var ctx = new QuestionWriteContext(questions);

            _dbContext.QuestionModel.AttachRange(questions);
            var ctx = new QuestionWriteContext(new EFList <QuestionModel>(_dbContext.QuestionModel));

            var expr = from CreateQuestionResult in QuestionContext.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       //select CreateQuestionResult;
                       from checkLanguageResult in QuestionContext.CheckLanguage(new CheckLanguageCmd(cmd.Description))
                       from sendAckToQuestionOwnerCmd in QuestionContext.SendQuestionOwnerAcknowledgment(new SendQuestionOwnerAcknowledgementCmd(1, 2))
                       select CreateQuestionResult;

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


            _dbContext.QuestionModel.Add(new DatabaseModel.Models.QuestionModel {
                QuestionId = Guid.NewGuid(), Title = cmd.Title, Description = cmd.Description, Tags = cmd.Tags
            });
            //var reply = await _dbContext.QuestionModel.Where(r => r.Title == "Intrebarea1").SingleOrDefaultAsync();
            //_dbContext.QuestionModel.Update(reply);
            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       succ => (IActionResult)Ok("Successfully"),
                       fail => BadRequest("Reply could not be added")
                       ));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Question>(_dbContext.Question),
                new EFList <User>(_dbContext.User));

            var dependencies = new QuestionDependencies();

            dependencies.GenerateInvitationToken = () => Guid.NewGuid().ToString();
            dependencies.SendInvitationEmail     = (InvitationLetter letter) => async() => new InvitationAcknowledgement(Guid.NewGuid().ToString());

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       let question = createQuestionResult.SafeCast <CreateQuestionResult.QuestionCreated>().Select(p => p.question)
                                      let createQuestionCmd = new CreateQuestionCmd(question)
                                                              from CreateQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                                                              select new { createQuestionResult, CrateQuestionResult };

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

            _dbContext.SaveChanges();
            return(r.createQuestiontResult.Match(
                       created => (IActionResult)Ok(created.question.TenantId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Tenant could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> CreateAndConfirmationQuestion([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post),
                new EFList <User>(_dbContext.User));

            var dependencies = new QuestionDependencies();

            dependencies.GenerateConfirmationToken = () => Guid.NewGuid().ToString();
            dependencies.SendConfirmationEmail     = SendConfirmationEmail;

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       let user = createQuestionResult.SafeCast <CreateQuestionResult.QuestionCreated>().Select(p => p.Author)
                                  let confirmationQuestionCmd = new ConfirmationQuestionCmd(user)
                                                                from ConfirmationQuestionResult in QuestionDomain.ConfirmQuestion(confirmationQuestionCmd)
                                                                select new { createQuestionResult, ConfirmationQuestionResult };
            var r = await _interpreter.Interpret(expr, ctx, dependencies);

            // _dbContext.Post.Add(new Post { PostTypeId=1,Title=createQuestionCmd.Title, PostText=createQuestionCmd.Body});
            await _dbContext.SaveChangesAsync();

            return(r.createQuestionResult.Match(
                       created => (IActionResult)Ok(created.Question.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
        // 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()
                                ));
        }
Ejemplo n.º 7
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.")));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> CreateQuestion(CreateQuestionCmd cmd)
        {
            var dep = new QuestionDependencies();
            var ctx = new QuestionWriteContext();

            var expr = from createTenantResult in QuestionContext.CreateQuestion(cmd)
                       select createTenantResult;

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

            return(r.Match(
                       created => Ok(created),
                       notCreated => BadRequest(notCreated),
                       invalidRequest => ValidationProblem()
                       ));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateQuestionAndSendEmail([FromBody] ValidateQuestionCmd validateQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            var expr = from validateQuestionResult in QuestionDomain.ValidateQuestion(validateQuestionCmd)
                       let post = validateQuestionResult.SafeCast <QuestionValidated>().Select(p => p.Post)
                                  select new { validateQuestionResult };

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

            _dbContext.SaveChanges();
            return(r.validateQuestionResult.Match(
                       created => (IActionResult)Ok(created.Post.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            dependencies.QuestionEmail = SendEmail;

            var exp = from CreateQuestionResult in QuestionContext.CreateQuestion(cmd)
                      select CreateQuestionResult;
            var r = await _interpreter.Interpret(exp, ctx, dependencies);

            _dbContext.SaveChanges();

            return(r.Match(
                       created => (IActionResult)Ok("Question posted"),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be posted.")
                       ));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> CreateQuestionAsyncAndConfirmation([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new List <QuestionSummary>());
            var dependecies          = new QuestionDependencies();

            dependecies.SendConfirmationEmail = (ConfirmationLetter letter) => async() => new ConfirmationAcknowledgement(Guid.NewGuid().ToString());

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       let questionSummary = createQuestionResult.SafeCast <CreateQuestionResult.QuestionCreated>().Select(p => p.QuestionSummary)
                                             let confirmationCmd = new ConfirmationQuestionCmd(questionUser)
                                                                   from confirmationResult in QuestionDomain.ConfirmQuestion(confirmationCmd)
                                                                   select new { createQuestionResult, confirmationResult };
            var r = await _interpreter.Interpret(expr, ctx, dependecies);

            return(r.createQuestionResult.Match(
                       created => (IActionResult)Ok(created.QuestionSummary.QuestionId),
                       notCreated => BadRequest("Question could not be created."),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Ejemplo n.º 12
0
        public async Task <ActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));
            var dependencies         = new QuestionDependencies();

            dependencies.SendConfirmationEmail = (ConfirmationLetter response) => async() => new ConfirmationAcknowledgement(Guid.NewGuid().ToString());

            var expr = from questionResult in QuestionDomain.CreateQuestion(cmd)
                       select questionResult;

            var result = await _interpreter.Interpret(expr, ctx, dependencies);

            _dbContext.SaveChanges();

            return(result.Match(
                       created => Ok(created),
                       notCreated => (ActionResult)BadRequest("Question not created"),
                       invalidRequest => BadRequest("Invalid request")));
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            var questionDependencies = new QuestionDependencies();

            //var questionWriteContext= await _db_Context.Question.ToList();


            var questionWriteContext = new QuestionWriteContext(new EFList <Question>(_db_Context.Question));


            var expr = from createQuestionResult in QuestionsDomain.CreateQuestion(cmd)

                       /* from checkLanguageResult in QuestionsDomain.CheckLanguage(new CheckLanguageCmd(cmd.Body))
                        * from sendAckToQuestionOwnerCmd in QuestionsDomain.SendAckToQuestionOwner(new ReceivedAckSentToQuestionOwnerCmd(1, 2))*/
                       select createQuestionResult;

            var result = await _interpreter.Interpret(expr, questionWriteContext, new object());

            // var result = await _interpreter.Interpret(expr, questionWriteContext, questionDependencies);

            //_db_Context.Question.Add(new DatabaseModel.Models.Question { QuestionId = 1, Title = cmd.Title, Body = cmd.Body, Tags = cmd.Tags });
            // var question = await _dbContext.Question.Where(r => r.QuestionId == 1).SingleOrDefaultAsync();

            // _dbContext.Question.Update(question);

            await _dbContext.SaveChangesAsync();

            return(result.Match(
                       create => (CreateTenantResult.TenantCreated)(IActionResult) Ok(create.QuestionId),
                       notcreated => BadRequest("NotPosted"),
                       invalidRequest => ValidationProblem()
                       ));

            /* return result.createQuestionResult.Match(
             *   created => (IActionResult)Ok(qe
             *       QuestionPosted),
             *   notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
             *   invalidRequest => BadRequest("Invalid request."));
             * /*return result.Match(created => (IActionResult)Ok(created),
             *     notCreated => BadRequest(notCreated),
             *     invalidRequest => ValidationProblem()
             *  );*/
        }
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            var dep       = new QuestionDependencies();
            var questions = await _dbContext.Questions.ToListAsync();

            var ctx  = new QuestionWriteContext(new EFList <Questions>(_dbContext.Questions));
            var expr = from createQuestionResult in QuestionContext.CreateQuestion(cmd) select createQuestionResult;
            var r    = await _interpreter.Interpret(expr, ctx, dep);

            _dbContext.Questions.Add(new DatabaseModel.Models.Questions {
                QuestionId = Guid.NewGuid(), Title = cmd.Title, Body = cmd.Body, Tags = cmd.Tags
            });
            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       created => (IActionResult)Ok(created.Body),
                       notcreated => BadRequest("NotPosted"),
                       invalidRequest => ValidationProblem()
                       ));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> CreateReply(int questionId, [FromBody] GetQuestionReplyCmd getQuestionReplyCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post),
                new EFList <User>(_dbContext.User));


            var dependencies = new QuestionDependencies();
            var expr         = from createQuestionResult in QuestionDomain.GetQuestionReply(getQuestionReplyCmd)
                               select createQuestionResult;


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

            _dbContext.SaveChanges();
            return(r.Match(
                       created => Ok(created.Replies.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
        public async Task <IActionResult> CreateQuestion([FromBody] QuestionCmd cmd)
        {
            var dep = new QuestionDependencies();

            //var question = await _dbContext.QuestionDB.ToListAsync();

            var ctx = new WriteContext();

            var expr = from CreateTenantResult in QuestionContext.CreateQuestion(cmd)
                       select CreateTenantResult;

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

            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       succ => (IActionResult)Ok(succ),
                       fail => BadRequest("Error")
                       ));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> CreateQuestionAsyncAndSendEmail([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            dependencies.SendConfirmationEmail = (ConfirmationLetter letter) => async() => new ConfirmationAcknowledgement(Guid.NewGuid().ToString());
            dependencies.SendConfirmationEmail = SendEmail;

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       select createQuestionResult;

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

            _dbContext.SaveChanges();
            return(r.Match(
                       created => Ok(created.Question.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Ejemplo n.º 18
0
        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.")));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCommand cmd)
        {
            var posts = _dbContext.Post.ToList();
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            dependencies.SendConfirmationEmail = SendEmail;

            var expr = from questionResult in QuestionDomain.CreateQuestion(cmd.QuestionId, cmd.QuestionText, cmd.Title, cmd.Tags)
                       select questionResult;

            var result = await _interpreter.Interpret(expr, ctx, dependencies);

            _dbContext.SaveChanges();

            return(result.Match(
                       created => Ok(created),
                       notCreated => (ActionResult)BadRequest($"Question  with title {cmd.Title} could not be created"),
                       invalidRequest => BadRequest("Invalid request")));

            //return Ok();
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> CreateReply(int questionId, [FromBody] GetQuestionReplyCmd getQuestionReplyCmd)
        {
            // o noua comanda, o operatiune de comanda si din ea sa trimitem un mesaj prin streamul de eventuri ca sa ne dam seama ca s-a create un nou reply
            // trimitem un mesaj printr-un stream catre un grain
            // id-ul grainului este id-ul intrebarii

            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post),
                new EFList <User>(_dbContext.User),
                new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            var expr = from createQuestionResult in QuestionDomain.GetQuestionReply(getQuestionReplyCmd)
                       select createQuestionResult;

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

            _dbContext.SaveChanges();
            return(r.Match(
                       created => Ok(created.Replies.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }