public async Task <IActionResult> CreateReply([FromBody] CreateReplyCmd cmd)
        {
            var dep = new QuestionsDependencies();
            //var ctx = new QuestionsWriteContext();
            var replies = await _dbContext.Replies.ToListAsync();

            //var ctx = new QuestionsWriteContext(replies);
            _dbContext.Replies.AttachRange(replies);
            var ctx = new QuestionsWriteContext(new EFList <Reply>(_dbContext.Replies));

            var expr = from createTenantResult in QuestionsContext.CreateReply(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd(cmd.Body)
                       from checkLanguageResult in QuestionsContext.CheckLanguage(new CheckLanguageCmd(cmd.Body))
                       from sendAckAuthor in QuestionsContext.SendQuestionAuthorAcknowledgement(new SendQuestionAuthorAcknowledgementCmd(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 = 8
            });
            //var reply = await _dbContext.Replies.Where(r => r.ReplyId == 2).SingleOrDefaultAsync();
            //reply.Body = "Text updated";
            //_dbContext.Replies.Update(reply);
            await _dbContext.SaveChangesAsync();

            return(r.Match(
                       succ => (IActionResult)Ok("Succeeded"),
                       fail => BadRequest("Reply could not be added")
                       ));
        }
Example #2
0
        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")
                       ));
        }
Example #3
0
        public IList <Question> GetQuestion(string filter = null, int limit = 0, int offset = 0)
        {
            IList <Question> returnValue = null;

            bool useSkipAndTake = limit > 0 && offset > 0;

            using (var ctx = new QuestionsContext())
            {
                // Change this to using a dynamic predicate
                if (string.IsNullOrEmpty(filter))
                {
                    if (useSkipAndTake)
                    {
                        returnValue = ctx.Questions.OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
                    }
                    else
                    {
                        returnValue = ctx.Questions.OrderBy(x => x.ID).ToList();
                    }
                }
                else
                {
                    if (useSkipAndTake)
                    {
                        returnValue = ctx.Questions.Where(x => x.Description.Contains(filter)).OrderBy(x => x.ID).Skip(offset).Take(limit).ToList();
                    }
                    else
                    {
                        returnValue = ctx.Questions.Where(x => x.Description.Contains(filter)).OrderBy(x => x.ID).ToList();
                    }
                }
            }

            return(returnValue);
        }
        public async Task <IActionResult> CreateQuestion([FromBody] CreateQuestionsCmd cmd)
        {
            var dep = new QuestionsDependencies();

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

            //var ctx = new QuestionsWriteContext(questions);
            _dbContext.Questions.AttachRange(questions);

            var ctx = new QuestionsWriteContext(new EFList <Question>(_dbContext.Questions));

            var expr = from createQuestionResult in QuestionsContext.CreateQuestion(cmd)
                       //let checkLanguageCmd = new CheckLanguageCmd()
                       from checkLanguageResult in QuestionsContext.CheckLanguage(new CheckLanguageCmd(cmd.Description))
                       from sendAckAuthor in QuestionsContext.SendQuestionAuthorAcknowledgement(new SendQuestionAuthorAcknowledgementCmd(Guid.NewGuid(), 1, 2))
                       select createQuestionResult;

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

            _dbContext.Questions.Add(new DatabaseModel.Models.Question {
                QuestionId = cmd.QuestionId, Title = cmd.Title, Description = cmd.Description, Tags = cmd.Tags
            });
            await _dbContext.SaveChangesAsync();

            var reply = await _dbContext.Questions.Where(r => r.QuestionId == cmd.QuestionId).SingleOrDefaultAsync();

            _dbContext.Questions.Update(reply);

            return(r.Match(
                       succ => (IActionResult)Ok("Succeeded"),
                       fail => BadRequest("Question could not be added")
                       ));
        }
Example #5
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")
                       ));
        }
Example #6
0
        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 = new Guid("9431a4d2-ce83-4ae6-ac13-2f0b2b1d31de"), 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")
                       ));
        }
Example #7
0
        public Question Save(Question entity)
        {
            using (var ctx = new QuestionsContext())
            {
                ctx.Questions.Add(entity);
                ctx.SaveChanges();
            }

            return(entity);
        }
Example #8
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
     if (env.IsDevelopment())
     {
         app.UseDeveloperExceptionPage();
         app.UseCors("CorsPolicy");
     }
     app.UseMvc();
     QuestionsContext.SeedData(app.ApplicationServices);
 }
 public QuestionsController(QuestionsContext context)
 {
     this.db = context;
     if (!db.Questions.Any())
     {
         db.Questions.Add(new Question {
             QuestionText = "Чем меряются⁣ ⁣между ⁣собой любители армрестлинга?", Answers = "Силой рук || Остротой зубов || Быстротой ног || Размерами животов"
         });
         db.SaveChanges();
     }
 }
Example #10
0
 // Getting all questions and answers from database to List of type Questions
 private void GetAllQuestions()
 {
     using (QuestionsContext context = new QuestionsContext())
     {
         var result = context.Questions.ToList();
         foreach (var r in result)
         {
             allQuestions.Add(r);
         }
     }
 }
Example #11
0
        public Question GetQuestion(long idQuestion)
        {
            Question returnValue = null;

            using (var ctx = new QuestionsContext())
            {
                returnValue = ctx.Questions.Find(idQuestion);
            }

            return(returnValue);
        }
Example #12
0
        public bool DeleteById(long idQuestion)
        {
            bool returnValue = false;

            using (var ctx = new QuestionsContext())
            {
                var entRemove = ctx.Questions.Find(idQuestion);
                ctx.Questions.Remove(entRemove);
                ctx.SaveChanges();

                returnValue = true;
            }
            return(returnValue);
        }
Example #13
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env,
                              ILoggerFactory loggerFactory,
                              QuestionsContext questionsContext)
        {
            loggerFactory.AddConsole(this.Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseCors(builder => builder.AllowAnyOrigin());

            app.UseMvc();

            DbInitializer.Initialize(env.IsDevelopment(), questionsContext);
        }
Example #14
0
        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")
                       ));
        }
Example #15
0
        public bool Health()
        {
            bool returnValue = true;

            using (var ctx = new QuestionsContext())
            {
                var item = ctx.Questions.FirstOrDefault();

                if (item == null)
                {
                    returnValue = false;
                }
            }

            return(returnValue);
        }
Example #16
0
        // GET: DisplayQuestions


        public ActionResult Index12()
        {
            //Timer


            int           numberapti   = 20;
            int           numberjava   = 10;
            int           numberpython = 10;
            int           numbercsharp = 10;
            int           experience   = 2;
            List <string> Technology   = new List <string>
            {
                "java", "csharp"
            };

            string querypython = String.Format("select top {0} * from Java_tbl1 where TECHST=2 order by newid()  ", numberpython);
            IEnumerable <Java_tbl1> listpython = dbcontext.Java_tbl1.SqlQuery(querypython).ToList();
            string queryjava = String.Format("select top {0} * from Java_tbl1  where TECHST=1 order by newid()", numberjava);
            IEnumerable <Java_tbl1> listjava = dbcontext.Java_tbl1.SqlQuery(queryjava).ToList();
            string querycsharp = String.Format("select top {0} * from Java_tbl1 where TECHST=3 order by newid()  ", numbercsharp);
            IEnumerable <Java_tbl1> listcsharp = dbcontext.Java_tbl1.SqlQuery(querycsharp).ToList();
            string queryaptitude = String.Format("select top {0} * from Java_tbl1 where TECHST=4 order by newid()  ", numberapti);
            IEnumerable <Java_tbl1> listaptitude = dbcontext.Java_tbl1.SqlQuery(queryaptitude).ToList();

            //IEnumerable<Java_tbl1> listall = listapti.Concat(listjava);
            //TempData["all"] = listall;

            TempData["python"] = listpython;
            TempData["java"]   = listjava;
            TempData["csharp"] = listcsharp;
            TempData["apti"]   = listaptitude;

            var model = new QuestionsContext
            {
                Questions_python = listpython,
                Questions_java   = listjava,
                Questions_csharp = listcsharp,
                Questions_apti   = listaptitude
            };

            if (Session["Rem_Time"] == null)
            {
                Session["Rem_Time"] = DateTime.Now.AddMinutes(1).ToString("dd-MM-yyyy h:mm:ss tt");
            }
            ViewBag.Rem_Time = Session["Rem_Time"];
            return(View(model));
        }
Example #17
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());
        }
Example #18
0
        public Question Update(Question entity)
        {
            Question returnValue = null;

            using (var ctx = new QuestionsContext())
            {
                returnValue = ctx.Questions.Find(entity.ID);

                if (returnValue == null)
                {
                    throw new QuestionLibaryException("The item with [ID={0}] does not exist.", entity.ID.ToString());
                }

                returnValue.Description = entity.Description;
                returnValue.Number      = entity.Number;

                ctx.SaveChanges();
            }

            return(returnValue);
        }
Example #19
0
        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")
                       ));
        }
Example #20
0
 public QuestionnairesUnitOfWork(QuestionsContext context, IQuestionnairesRepo repo) : base(context)
 {
     this.QuestionnairesRepo = repo;
     this.Context            = context;
 }
Example #21
0
 private QuestionsApp.Web.Api.Controllers.Queries.QuestionsController NewQuery(QuestionsContext context)
 {
     return(new Web.Api.Controllers.Queries.QuestionsController(context));
 }
Example #22
0
 public QuestionRepository(QuestionsContext qestionsContext)
 {
     this.qestionsContext = qestionsContext;
 }
Example #23
0
 public QuestionsRepository(QuestionsContext context) : base(context)
 {
 }
Example #24
0
 private QuestionsApp.Web.Api.Controllers.Commands.QuestionsController NewCommand(QuestionsContext context)
 {
     return(new Web.Api.Controllers.Commands.QuestionsController(context, null));
 }
Example #25
0
 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 public void Configure(QuestionsContext questionsContext)
 {
     DbInitializer.Initialize(false, questionsContext);
 }
Example #26
0
 public QuestionService(IMapper mapper, QuestionsContext context)
 {
     _mapper  = mapper;
     _context = context;
 }
 public QuestionsController(QuestionsContext context)
 {
     _context = context;
 }
Example #28
0
 public QuestionsController(QuestionsContext context, IHubContext <QuestionsHub> hub)
 {
     _context = context;
     _hub     = hub;
 }
 public QuestionManager(QuestionsContext db)
 {
     this.db = db;
 }