Beispiel #1
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            QuestionsWriteContext ctx = new QuestionsWriteContext(
                new EFList <Post>(_dbContext.Post));

            var dep = new QuestionsDependencies();

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

            //var questions = await _dbContext.Post.Where(q => q.PostTypeId == 1).ToListAsync();
            _dbContext.Post.AttachRange(questions);

            var expr = from createQuestionResult in QuestionsDomain.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       //select CreateQuestionResult;
                       from checkLanguageResult in QuestionsDomain.CheckLanguage(new CheckLanguageCmd(cmd.PostText))
                       //from sendAckToQuestionOwnerCmd in QuestionsDomain.SendQuestionOwnerAcknowledgement(new SendQuestionOwnerAcknowledgementCmd())
                       select new { createQuestionResult, checkLanguageResult };

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

            //var reply = await _dbContext.QuestionModel.Where(r => r.Title == "intrebTest").SingleOrDefaultAsync();
            //_dbContext.Question.Update(reply);
            //await _dbContext.SaveChangesAsync();

            _dbContext.SaveChanges();

            return(r.createQuestionResult.Match(
                       created => (IActionResult)Ok("PostID of question created:" + created.question.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Beispiel #2
0
        public async Task <IActionResult> CreateQuestionAsync([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            var ctx = new QuestionsWriteContext(new EFList <Post>(_dbContext.Post), new EFList <User>(_dbContext.User));

            var dependencies = new QuestionsDependency();

            dependencies.GenerateConfirmationToken = () => Guid.NewGuid().ToString();
            dependencies.SendConfirmationEmail     = SendEmailToOwner;

            var expr = from createResult in QuestionsDomain.CreateQuestion(createQuestionCmd)
                       let title                                                     = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.Title)
                                                        let body                     = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.Body)
                                                                             let tag = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.Tag)
                                                                                       let tenantId = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.TenantId)
                                                                                                      let userId                       = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.UserId)
                                                                                                                              let user = createResult.SafeCast <CreateQuestionResult.QuestPublished>().Select(p => p.User)
                                                                                                                                         let confirmQuest = new CreateQuestionCmd((string)title, (string)body, (string)tag, (int)tenantId, (Guid)userId, (TenantUser)user)
                                                                                                                                                            from CreateQuestionResult in QuestionsDomain.CreateQuestion(confirmQuest)
                                                                                                                                                            select new { createResult, CreateQuestionResult };

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

            _dbContext.SaveChanges();

            return(r.createResult.Match(
                       created => (IActionResult)Ok(created.Title),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),
                       invalidRequest => BadRequest("Invalid request.")));
        }
        public ActionResult Create([Bind(Include = "ID,Title,Body,Date")] Question question)
        {
            if (ModelState.IsValid)
            {
                db.Questions.Add(question);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(question));
        }
Beispiel #4
0
        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     = SendEmail;

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       let user = createQuestionResult.SafeCast <CreateQuestionResult.QuestionCreated>().Select(p => p.Author)
                                  let confirmationCmd = new ConfirmationCmd(user)
                                                        from ConfirmationResult in QuestionDomain.ConfirmQuestion(confirmationCmd)
                                                        select new { createQuestionResult, ConfirmationResult };
            var r = await _interpreter.Interpret(expr, ctx, dependencies);

            _dbContext.SaveChanges();
            return(r.createQuestionResult.Match(
                       created => Ok(created),
                       // created => (IActionResult)Ok(created.Question.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Beispiel #5
0
        public async Task <IActionResult> CreateTenantAsyncAndInviteAdmin([FromBody] CreateTenantCmd createTenantCmd)
        {
            BackofficeWriteContext ctx = new BackofficeWriteContext(
                new EFList <Tenant>(_dbContext.Tenant),
                new EFList <TenantUser>(_dbContext.TenantUser),
                new EFList <User>(_dbContext.User));

            var dependencies = new BackofficeDependencies();

            dependencies.GenerateInvitationToken = () => Guid.NewGuid().ToString();
            dependencies.SendInvitationEmail     = SendEmail;

            var expr = from createTenantResult in BackofficeDomain.CreateTenant(createTenantCmd)
                       let adminUser = createTenantResult.SafeCast <CreateTenantResult.TenantCreated>().Select(p => p.AdminUser)
                                       let inviteAdminCmd = new InviteTenantAdminCmd(adminUser)
                                                            from inviteAdminResult in BackofficeDomain.InviteTenantAdmin(inviteAdminCmd)
                                                            select new { createTenantResult, inviteAdminResult };

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

            _dbContext.SaveChanges();
            return(r.createTenantResult.Match(
                       created => (IActionResult)Ok(created.Tenant.TenantId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Tenant could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Beispiel #6
0
        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.")));
        }
Beispiel #7
0
        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 <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 <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> GetTenants()
        {
            /*var tenant = new Tenant()
             * {
             *  Name = "test3",
             *  Description = "bla bla3",
             *  OrganisationId = Guid.NewGuid()
             * };
             *
             * _dbContext.Tenant.Add(tenant);
             * _dbContext.SaveChanges(); */

            var tenants = _dbContext
                          .Tenant
                          .Where(p => p.Name.Equals("testPetrisoara")).ToList();

            // _dbContext.RemoveRange(tenants);
            _dbContext.SaveChanges();

            return(Ok(tenants));
        }
        public async Task <IActionResult> CreateTenantAsyncAndInviteAdmin([FromBody] CreateTenantCmd createTenantCmd)
        {
            BackofficeWriteContext ctx = new BackofficeWriteContext(
                new EFList <Tenant>(_dbContext.Tenant),

                new EFList <User>(_dbContext.User));


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

            _dbContext.SaveChanges();
            return(r.createTenantResult.Match(
                       created => (IActionResult)Ok(created.Tenant.TenantId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Tenant could not be created."),//todo return 500 (),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Beispiel #12
0
        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());

            _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> CreateQuestionAndSendEmail([FromBody] ValidateQuestionCmd validateQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            var expr = from validateQuestionResult in QuestionDomain.ValidateQuestion(validateQuestionCmd)
                       let post = validateQuestionResult.SafeCast <QuestionValidated>().Select(p => p.Post)
                                  select new { validateQuestionResult };

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

            _dbContext.SaveChanges();
            return(r.validateQuestionResult.Match(
                       created => (IActionResult)Ok(created.Post.PostId),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "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")));
        }
Beispiel #16
0
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionCmd cmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(new EFList <Post>(_dbContext.Post));

            var dependencies = new QuestionDependencies();

            dependencies.QuestionEmail = SendEmail;

            var exp = from CreateQuestionResult in QuestionContext.CreateQuestion(cmd)
                      select CreateQuestionResult;
            var r = await _interpreter.Interpret(exp, ctx, dependencies);

            _dbContext.SaveChanges();

            return(r.Match(
                       created => (IActionResult)Ok("Question posted"),
                       notCreated => StatusCode(StatusCodes.Status500InternalServerError, "Question could not be posted.")
                       ));
        }
Beispiel #17
0
        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> CreateQuestionAsyncAndConfirmation([FromBody] CreateQuestionCmd createQuestionCmd)
        {
            QuestionWriteContext ctx = new QuestionWriteContext(
                new EFList <Post>(_dbContext.Post));

            var dependecies = new QuestionDependencies();

            dependecies.SendConfirmationEmail = (ConfirmationLetter letter) => async() => new ConfirmationAcknowledgement(Guid.NewGuid().ToString());

            var expr = from createQuestionResult in QuestionDomain.CreateQuestion(createQuestionCmd)
                       let post = createQuestionResult.SafeCast <CreateQuestionResult.QuestionCreated>().Select(p => p.Post)
                                  let confirmationCmd = new ConfirmationQuestionCmd(questionUser)
                                                        from confirmationResult in QuestionDomain.ConfirmQuestion(confirmationCmd)
                                                        select new { createQuestionResult, confirmationResult };
            var r = await _interpreter.Interpret(expr, ctx, dependecies);

            _dbContext.SaveChanges();

            return(r.createQuestionResult.Match(
                       created => (IActionResult)Ok(created.Post.PostId),
                       notCreated => BadRequest("Question could not be created."),
                       invalidRequest => BadRequest("Invalid request.")));
        }
Beispiel #19
0
        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();
        }