Exemple #1
0
        public async Task <IActionResult> PostQuestion([FromBody] PostQuestionCmd cmd)
        {
            var dep = new QuestionsDependencies();

            dep.SendInvitationEmail = SendEmail;
            var questions = await _dbContext.Questions.ToListAsync();

            var ctx = new QuestionsWriteContext(questions);

            var expr = from postQuestionsResult in QuestionsContext.PostQuestion(cmd)
                       from sendOwnerAck in QuestionsContext.SendQuestionOwnerAcknowledgement(new SendQuestionOwnerAcknowledgementCmd(new Guid("f505c32f-3573-4459-8112-af8276d3e919"), "*****@*****.**"))
                       select postQuestionsResult;

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

            _dbContext.Questions.Add(new DatabaseModel.Models.Post {
                PostId = cmd.QuestionId, Title = cmd.Title, PostText = cmd.Body, PostedBy = new Guid("f505c32f-3573-4459-8112-af8276d3e919")
            });
            //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.QuestionId),
                       fail => BadRequest("Question could not be added"),
                       invalid => BadRequest("Invalid Question")
                       ));
        }
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionsCmd cmd)
        {
            var dep = new QuestionsDependencies();

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

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

            // var expr = from createTenantResult in QuestionsContext.CreateQuestion(cmd)
            // select createTenantResult;
            var expr = from CreateQuestionResult in QuestionsContext.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       //select CreateQuestionResult;
                       from checkLanguageResult in QuestionsContext.CheckLanguage(new CheckLanguageCmd(cmd.Description))
                       from sendAckToQuestionOwnerCmd in QuestionsContext.SendQuestionOwnerAcknowledgement(new SendQuestionOwnerAcknowledgementCmd(1, 2))
                       select CreateQuestionResult;
            var r = await _interpreter.Interpret(expr, ctx, dep);

            await _dbContext.SaveChangesAsync();

            _dbContext.QuestionModel.Add(new DatabaseModel.Models.QuestionModel {
                Id = cmd.QuestionId, Title = cmd.Title, Description = cmd.Description, Tags = cmd.Tags
            });
            await _dbContext.SaveChangesAsync();

            // var reply = await _dbContext.QuestionModel.Where(r => r.Id == 1).SingleOrDefaultAsync();
            //_dbContext.QuestionModel.Update(reply);

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

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

            _dbContext.Question.AttachRange(questions);

            var ctx = new QuestionsWriteContext(new List <Question>());

            var expr = from CreateQuestionResult in QuestionsContext.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       //select CreateQuestionResult;
                       from checkLanguageResult in QuestionsContext.CheckLanguage(new CheckLanguageCmd(cmd.Body))
                       from sendAckToQuestionOwnerCmd in QuestionsContext.SendQuestionOwnerAcknowledgement(new SendQuestionOwnerAcknowledgementCmd(1, 1))
                       select CreateQuestionResult;

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


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

            return(r.Match(
                       succ => (IActionResult)Ok("Question successfully added"),
                       fail => BadRequest("Question could not be added")
                       ));
        }