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] 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()); }