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