Exemplo n.º 1
0
        public IActionResult DeleteOEQfromP(int oeQid, int exercisePaperId)
        {
            DbSet <ExercisePaper> expp     = _dbContext.ExercisePaper;
            ExercisePaper         exppList = expp.Where(c => c.ExercisePaperId == exercisePaperId).FirstOrDefault();

            DbSet <OExPaperList> exP     = _dbContext.OExPaperList;
            OExPaperList         expItem = exP.Where(c => c.ExercisePaperId == exercisePaperId && c.OEQuestionId == oeQid).FirstOrDefault();

            DbSet <OEQuestions> oeQT    = _dbContext.OEQuestions;
            OEQuestions         oeQitem = oeQT.Where(c => c.Id == oeQid).FirstOrDefault();

            oeQitem.UseCount = oeQitem.UseCount + 1;

            exppList.TotalQns = exppList.TotalQns - 1;


            _dbContext.ExercisePaper.Update(exppList);
            if (expItem != null)
            {
                _dbContext.OExPaperList.Remove(expItem);
            }
            _dbContext.SaveChanges();


            return(Ok());
        }
Exemplo n.º 2
0
        public IActionResult AddQuestion(int id)
        {
            DbSet <OEQuestions> oeQT      = _dbContext.OEQuestions;
            DbSet <Topics>      topics    = _dbContext.Topics;
            List <Topics>       topicList = topics.ToList();
            var topic = topicList.Where(c => c.Id.Equals(id)).FirstOrDefault();
            List <OEQuestions> oeQList     = oeQT.Where(c => c.Topic == topic.Name && c.UseCount > 0).ToList();
            List <OEQuestions> reformatted = new List <OEQuestions>();

            if (topic.Id == 0)
            {
                List <OEQuestions> allOEq = oeQT.Where(c => c.UseCount > 0).ToList();

                foreach (var item in allOEq)
                {
                    var figure = item.Figure.Replace("[nline]", "<br>");

                    var question = item.Question.Replace("[nline]", "<br>");

                    var answer = item.Answer.Replace("[nline]", "<br>");

                    OEQuestions oe = new OEQuestions();
                    oe.Topic    = item.Topic;
                    oe.Figure   = figure;
                    oe.Question = question;
                    oe.Answer   = answer;
                    oe.Id       = item.Id;
                    oe.UseCount = item.UseCount;

                    reformatted.Add(oe);
                }

                return(Ok(reformatted));
            }

            foreach (var item in oeQList)
            {
                var figure = item.Figure.Replace("[nline]", "<br>");

                var question = item.Question.Replace("[nline]", "<br>");

                var answer = item.Answer.Replace("[nline]", "<br>");

                OEQuestions oe = new OEQuestions();
                oe.Topic    = item.Topic;
                oe.Figure   = figure;
                oe.Question = question;
                oe.Answer   = answer;
                oe.Id       = item.Id;
                oe.UseCount = item.UseCount;

                reformatted.Add(oe);
            }

            return(Ok(reformatted));
        }
Exemplo n.º 3
0
        public IActionResult EditOEQP(int oeQid, int exercisePaperId)
        {
            DbSet <OEQuestions> oeQ     = _dbContext.OEQuestions;
            OEQuestions         oeQItem = oeQ.Where(c => c.Id == oeQid).FirstOrDefault();

            DbSet <ExercisePaper> expp     = _dbContext.ExercisePaper;
            ExercisePaper         exppList = expp.Where(c => c.ExercisePaperId == exercisePaperId).FirstOrDefault();

            DbSet <OExPaperList> exP     = _dbContext.OExPaperList;
            List <OExPaperList>  exPList = exP.Where(c => c.OEQuestionId == oeQid).ToList();

            DbSet <OEQuestionsPaper> oeqP     = _dbContext.OEQuestionsPaper;
            List <OEQuestionsPaper>  oeqPList = oeqP.ToList();

            if (oeQItem.UseCount < 1)
            {
                if (!(oeqPList.Where(c => c.Id == oeQid).Count() > 0))
                {
                    OEQuestionsPaper oeqpS = new OEQuestionsPaper();
                    oeqpS.Question = oeQItem.Question;
                    oeqpS.Figure   = oeQItem.Figure;
                    oeqpS.Answer   = oeQItem.Answer;
                    oeqpS.Topic    = oeQItem.Topic;

                    if (exPList.Count() == 0)
                    {
                        OExPaperList expItem = new OExPaperList();
                        expItem.ExercisePaperId = exercisePaperId;
                        expItem.OEQuestionId    = oeQid;
                        _dbContext.OExPaperList.Add(expItem);
                    }


                    _dbContext.OEQuestionsPaper.Add(oeqpS);
                }
                else
                {
                    OExPaperList expItem = new OExPaperList();
                    expItem.ExercisePaperId = exercisePaperId;
                    expItem.OEQuestionId    = oeQid;
                    _dbContext.OExPaperList.Add(expItem);
                }
                exppList.TotalQns = exppList.TotalQns + 1;

                _dbContext.ExercisePaper.Update(exppList);
                _dbContext.SaveChanges();

                var figure = oeQItem.Figure.Replace("[nline]", "<br>");

                var question = oeQItem.Question.Replace("[nline]", "<br>");

                var answer = oeQItem.Answer.Replace("[nline]", "<br>");

                OEQuestions oe = new OEQuestions();
                oe.Topic    = oeQItem.Topic;
                oe.Figure   = figure;
                oe.Question = question;
                oe.Answer   = answer;
                oe.Id       = oeQItem.Id;
                oe.UseCount = oeQItem.UseCount;

                oeQItem.UseCount = oeQItem.UseCount - 1;
                _dbContext.OEQuestions.Update(oeQItem);
                _dbContext.SaveChanges();

                return(Ok(oe));
            }
            return(Ok());
        }