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")
                       ));
        }
Exemple #2
0
        public static IPostQuestionResult PostQuestion(PostQuestionCmd postQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(postQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Invalid question title"
                };
                return(new QuestionValidationFailed(errors));
            }

            if (string.IsNullOrWhiteSpace(postQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invalid body for the question"
                };
                return(new QuestionValidationFailed(errors));
            }


            if (new Random().Next(10) > 1)
            {
                return(new QuestionNotPosted("Question could not be verified"));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionPosted(questionId, postQuestionCommand.Title, postQuestionCommand.Body, postQuestionCommand.Tags);

            //execute logic
            return(result);
        }
        static void Main(string[] args)
        {
            var cmd    = new PostQuestionCmd("What is the only prime and even number ? ");
            var result = PostQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Exemple #4
0
        static void Main(string[] args)
        {
            var cmd    = new PostQuestionCmd("Problem with class definition", "Errors keep appearing when defining class", "code1", "C#");
            var result = PostQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );


            Console.ReadLine();
        }
Exemple #5
0
        static void Main(string[] args)
        {
            List <string> tags = new List <string> {
                "React", "JavaScript"
            };
            var cmd    = new PostQuestionCmd("What are Components?", "Can somebody explain me how Components work in React", tags);
            var result = PostQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            List <string> tags = new List <string> {
                "CSS3", "SCSS"
            };
            var cmd    = new PostQuestionCmd("How can we change bullet styling for an unordered list element?", "Can somebody give me a concrete example?", tags);
            var result = PostQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Exemple #7
0
        static void Main(string[] args)
        {
            List <string> tags = new List <string> {
                "Redux", "Typescript"
            };
            var cmd    = new PostQuestionCmd("Do we need an interface for our initialValues in Redux?", "Can someone give me an example?", tags);
            var result = PostQuestion(cmd);

            result.Match(
                ProcessQuestionPosted,
                ProcessQuestionNotPosted,
                ProcessInvalidQuestion
                );

            Console.ReadLine();
        }
Exemple #8
0
        public static IPostQuestionResult PostQuestion(PostQuestionCmd postQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(postQuestionCommand.Title))
            {
                var errors = new List <string>()
                {
                    "Invalid title "
                };
                return(new QuestionValidationFailed(errors));
            }


            var questionId = Guid.NewGuid();
            var result     = new QuestionPosted(questionId, postQuestionCommand.Title, postQuestionCommand.Problem, postQuestionCommand.Code, postQuestionCommand.Tag);

            //execute logic
            return(result);
        }
Exemple #9
0
        public async Task <IActionResult> CreateQuestion([FromBody] PostQuestionCmd cmd)
        {
            var dep       = new QuestionsDependencies();
            var questions = await _dbContext.Questions.ToListAsync();

            var ctx  = new QuestionsWriteContext(questions);
            var expr = from createQuestionResult in QuestionsContext.PostQuestion(cmd)
                       select createQuestionResult;
            var r = await _interpreter.Interpret(expr, ctx, dep);

            _dbContext.Questions.Add(new DatabaseModel.Models.Question {
                QuestionId = cmd.QuestionId, Title = cmd.Title, Body = cmd.Body, Tags = cmd.Tags, Votes = cmd.Votes
            });
            //var reply = await _dbContext.Replies.Where(r => r.ReplyId == 4).SingleOrDefaultAsync();
            //reply.Body = "Text updated";
            //_dbContext.Replies.Update(reply);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
        public static IPostQuestionResult PostQuestion(PostQuestionCmd postQuestionCommand)
        {
            if (string.IsNullOrWhiteSpace(postQuestionCommand.Title))
            {
                return(new QuestionNotPosted("Insert a title!"));
            }
            if (string.IsNullOrWhiteSpace(postQuestionCommand.Body))
            {
                var errors = new List <string>()
                {
                    "Invalid description !"
                };
                return(new QuestionValidationFailed(errors));
            }

            var questionId = Guid.NewGuid();
            var result     = new QuestionPosted(questionId, postQuestionCommand.Title, postQuestionCommand.Tags, postQuestionCommand.Body);

            return(result);
        }
Exemple #11
0
 public static Port <IPostQuestionResult> PostQuestion(PostQuestionCmd postQuestionCmd) =>
 NewPort <PostQuestionCmd, IPostQuestionResult>(postQuestionCmd);