예제 #1
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.")));
        }
예제 #2
0
        public async Task <ActionResult> CreateQuestion(int questionId, string title, string tags)
        {
            CreateQuestionCommand cmd = new CreateQuestionCommand();
            var questionWriteContext  = new QuestionWriteContext(new List <CreateQuestionCommand>()
            {
                new CreateQuestionCommand()
                {
                    QuestionId = 7
                },
                new CreateQuestionCommand()
                {
                    Title = "How to convert from Guid to string in C#?"
                },
                new CreateQuestionCommand()
                {
                    Tags = "C#"
                }
            });

            var expr = from questionResult in QuestionDomain.CreateQuestion(questionId, "123", "C#")
                       select questionResult;

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

            return(result.Match(
                       created => Ok(created),
                       notCreated => BadRequest(notCreated),
                       invalidRequest => ValidationProblem()));
        }
예제 #3
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.")));
        }
예제 #4
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")
                           ));
            }
예제 #5
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.")));
        }
예제 #6
0
        public async Task <string> CreateQuestion1([FromBody] CreateQuestionCmd question)
        {
            QuestionContext ctx = new QuestionContext(
                new EFList <Question>(_dbContext.Question));
            var dep = new QuestionDepend();
            var exp = from createQuestionResult in QuestionDomain.CreateQuestion(question)
                      select  new { createQuestionResult };


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

            Console.WriteLine("fddddddddddddd");

            _dbContext.SaveChanges();
            if (_client.IsInitialized == false)
            {
                await _client.Connect();
            }
            var friend = _client.GetGrain <IEmailSender>(0);
            var a      = _dbContext.Utilizatori.Where(c => c.IdUser == question.IdUser);

            foreach (Utilizatori u in a)
            {
                var response = await friend.SendEmailAsync(u.Email);
            }


            return("adaugat");
        }
예제 #7
0
        public async Task <string> CreateQuestion1([FromBody] CreateQuestionCmd question)
        {
            QuestionContext ctx = new QuestionContext(
                new EFList <Question>(_dbContext.Question));
            var dep = new QuestionDepend();
            var exp = from createQuestionResult in QuestionDomain.CreateQuestion(question)
                      select  new { createQuestionResult };


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


            _dbContext.SaveChanges();

            return("adaugat");
        }
예제 #8
0
        public async Task <ActionResult> CreateQuestion([FromBody] CreateQuestionCommand cmd)
        {
            var posts = _dbContext.Post.ToList();
            QuestionWriteContext questionWriteContext = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post));

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

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

            return(result.Match(
                       created => Ok(created),
                       notCreated => BadRequest(notCreated),
                       invalidRequest => ValidationProblem()));
        }
예제 #9
0
        public async Task <IActionResult> CreateQuestionAsyncAndSendEmail([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post),
                new EFList <User>(_dbContext.User));

            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.")));
        }
예제 #10
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")
                       ));
        }
예제 #11
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.")));
        }
예제 #12
0
        public async Task <ActionResult> CreateQuestion([FromBody] CreateQuestionCommand cmd)
        {
            var posts = _dbContext.Post.ToList();
            QuestionWriteContext questionWriteContext = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post));

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

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

            _dbContext.SaveChanges();

            return(result.Match(
                       created => Ok(created),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Tenant could not be created."),
                       invalidRequest => BadRequest("Invalid request.")));
        }
        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())
                       ));
        }
예제 #14
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.")));
        }
예제 #15
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")));
        }
예제 #16
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.")));
        }
예제 #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.")));
        }
예제 #18
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();
        }
예제 #19
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.")));
        }
예제 #20
0
 public QuestionController()
 {
     _questionDomain = new QuestionDomain();
 }