public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd) { var dep = new QuestionsDependencies(); var replies = await _dbContext.Replies.ToListAsync(); _dbContext.Replies.AttachRange(replies); var ctx = new QuestionsWriteContext(new EFList <Reply>(_dbContext.Replies)); var expr = from createTenantResult in QuestionsContextOp.CreateReply(cmd) //let checkLanguageCmd = new CheckLanguageCmd() from checkLanguageResult in QuestionsContextOp.CheckLanguage(new CheckLanguageOpCmd(cmd.Body)) from sendAckAuthor in QuestionsContextOp.SendReplyAuthorAcknowledgement(new SendReplyAuthorAcknowledgementCmd(Guid.NewGuid(), 1, 2)) select createTenantResult; var r = await _interpreter.Interpret(expr, ctx, dep); //_dbContext.Replies.Add(new DatabaseModel.Models.Reply { Body = cmd.Body, AuthorUserId = 1, QuestionId = cmd.QuestionId, ReplyId = 4 }); //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.Body), fail => BadRequest("Reply could not be added") )); }
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") }); 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] 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") )); }
public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd) { var dep = new QuestionsDependencies(); var ctx = new QuestionsWriteContext(); var expr = from createTenantResult in QuestionsContext.CreateReply(cmd) select createTenantResult; var r = await _interpreter.Interpret(expr, ctx, dep); return(r.Match( succ => (IActionResult)Ok(succ.Body), fail => BadRequest("Reply could not be added") )); }
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 async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd) { var dep = new QuestionsDependencies(); var replies = await _dbContext.Replies.ToListAsync(); var ctx = new QuestionsWriteContext(replies); var expr = from createReplyResult in QuestionsContext.CreateReply(cmd) select createReplyResult; var r = await _interpreter.Interpret(expr, ctx, dep); _dbContext.Replies.Add(new DatabaseModel.Models.Reply { Body = cmd.Body, AuthorUserId = new Guid("f505c32f-3573-4459-8112-af8276d3e919"), QuestionId = cmd.QuestionId, ReplyId = 4 }); await _dbContext.SaveChangesAsync(); return(r.Match( succ => (IActionResult)Ok(succ.Body), fail => BadRequest("Reply could not be added") )); }
public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd) { var dep = new QuestionsDependencies(); var replies = await _dbContext.Replies.ToListAsync(); var ctx = new QuestionsWriteContext(replies); var expr = from createTenantResult in QuestionsContext.CreateReply(cmd) select createTenantResult; var r = await _interpreter.Interpret(expr, ctx, dep); //_dbContext.Replies.Add(new DatabaseModel.Models.Reply { Body = cmd.Body, AuthorUserId = 1, QuestionId = cmd.QuestionId, ReplyId = 4 }); //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.Body), fail => BadRequest("Reply could not be added") )); }