Example #1
0
        public ImageQuestion GetImageQuestion(int ID)
        {
            if (dbContext.ImageQuestion.Where(q => q.ID == ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + ID.ToString() + "`");
            }

            ImageQuestion question = new ImageQuestion();

            Models.DataModels.ImageQuestion iq = dbContext.ImageQuestion.Find(ID);

            question.ID       = iq.ID;
            question.X1       = iq.answerX1;
            question.Y1       = iq.answerY1;
            question.img      = iq.img;
            question.Question = iq.Question;

            if (iq.answerX2 != 0 && iq.answerX2 != null)
            {
                question.X2 = Convert.ToInt32(iq.answerX2);
            }

            if (iq.answerY2 != 0 && iq.answerY2 != null)
            {
                question.Y2 = Convert.ToInt32(iq.answerY2);
            }

            if (iq.answerRatio != 0 && iq.answerRatio != null)
            {
                question.Radius = Convert.ToInt32(iq.answerRatio);
            }

            return(question);
        }
Example #2
0
        public ImageQuestion GetImageQuestion(int ID)
        {
            if (_dbContext.ImageQuestion.Where(q => q.ID == ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + ID.ToString() + "`");
            }

            ImageQuestion Question = new ImageQuestion();

            Models.DataModels.ImageQuestion ImageQuestion = _dbContext.ImageQuestion.Find(ID);

            Question.ID       = ImageQuestion.ID;
            Question.X1       = ImageQuestion.AnswerX1;
            Question.Y1       = ImageQuestion.AnswerY1;
            Question.IMG      = ImageQuestion.IMG;
            Question.Question = ImageQuestion.Question;

            if (ImageQuestion.AnswerX2 != 0 && ImageQuestion.AnswerX2 != 0)
            {
                Question.X2 = Convert.ToInt32(ImageQuestion.AnswerX2);
            }

            if (ImageQuestion.AnswerY2 != 0 && ImageQuestion.AnswerY2 != 0)
            {
                Question.Y2 = Convert.ToInt32(ImageQuestion.AnswerY2);
            }

            if (ImageQuestion.AnswerRatio != 0 && ImageQuestion.AnswerRatio != 0)
            {
                Question.Radius = Convert.ToInt32(ImageQuestion.AnswerRatio);
            }

            return(Question);
        }
Example #3
0
        //Create

        public void CreateImageQuestion(ImageQuestion Question, HttpPostedFileBase File, int GameID)
        {
            if (_dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`");
            }
            if (Question.Question.Length < 5 || Question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (Question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (Question.X1 == 0 || Question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }
            if (File == null)
            {
                throw new Exception("Je moet een afbeelding uploaden!");
            }


            string IMG = UploadHandler.UploadImage(File, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;

            Question.IMG = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + IMG;

            Models.DataModels.ImageQuestion ImageQuestion = new Models.DataModels.ImageQuestion()
            {
                AnswerRatio = Question.Radius,
                AnswerX1    = Question.X1,
                AnswerX2    = Question.X2,
                AnswerY1    = Question.Y1,
                AnswerY2    = Question.Y2,
                Question    = Question.Question,
                IMG         = Question.IMG,
                ID          = Question.ID
            };
            _dbContext.ImageQuestion.Add(ImageQuestion);
            _dbContext.SaveChanges();

            int QuestionID = _dbContext.ImageQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            _dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup());
            _dbContext.SaveChanges();
            int ChartGroupID = _dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            Models.DataModels.Question NewQuestion = new Models.DataModels.Question()
            {
                ChartGroupID   = ChartGroupID,
                GameID         = GameID,
                QuestionType   = Models.DataModels.QuestionType.ImageQuestion,
                QuestionTypeID = QuestionID
            };

            _dbContext.Question.Add(NewQuestion);
            _dbContext.SaveChanges();
        }
Example #4
0
        //update

        public void UpdateImageQuestion(ImageQuestion question, HttpPostedFileBase file)
        {
            if (dbContext.ImageQuestion.Where(q => q.ID == question.ID).Count() == 0)
            {
                throw new Exception("Er is geen vraag gevonden met het ID : `" + question.ID.ToString() + "`");
            }
            if (question.Question.Length < 5 || question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (question.X1 == 0 || question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }


            if (file != null)
            {
                string img = UploadHandler.UploadImage(file, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;
                question.img = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + img;
            }

            Models.DataModels.ImageQuestion iq = dbContext.ImageQuestion.Where(q => q.ID == question.ID).First();
            iq.answerX1    = question.X1;
            iq.answerX2    = question.X2;
            iq.answerY1    = question.Y1;
            iq.answerY2    = question.Y2;
            iq.answerRatio = question.Radius;
            iq.Question    = question.Question;
            iq.img         = question.img;
            dbContext.SaveChanges();
        }
Example #5
0
        //Create

        public void CreateImageQuestion(ImageQuestion question, HttpPostedFileBase file, int GameID)
        {
            if (dbContext.Game.Where(g => g.ID == GameID).Count() == 0)
            {
                throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`");
            }
            if (question.Question.Length < 5 || question.Question.Length > 50)
            {
                throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!");
            }
            if (question.Question.Split(' ').Count() < 3)
            {
                throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!");
            }
            if (question.X1 == 0 || question.Y1 == 0)
            {
                throw new Exception("Er moet een antwoord gegeven worden!");
            }
            if (file == null)
            {
                throw new Exception("Je moet een afbeelding uploaden!");
            }


            string img = UploadHandler.UploadImage(file, UploadHandler.GetImageSize(PreDefImageSize.QuestionImage), PreDefImageLocation.QuestionImage).Name;

            question.img = "/" + UploadHandler.GetImageUrlPath(PreDefImageLocation.QuestionImage) + img;

            Models.DataModels.ImageQuestion imageQuestion = new Models.DataModels.ImageQuestion()
            {
                answerRatio = question.Radius,
                answerX1    = question.X1,
                answerX2    = question.X2,
                answerY1    = question.Y1,
                answerY2    = question.Y2,
                Question    = question.Question,
                img         = question.img,
                ID          = question.ID
            };
            dbContext.ImageQuestion.Add(imageQuestion);
            dbContext.SaveChanges();
            //string qry = "INSERT INTO `imagequestion` (`ID`, `img`, `question`, `answerX1`, `answerX2`, `answerY1`, `answerY2`, `answerRatio`) VALUES (NULL, '"+question.img+"', '"+question.Question+"', '"+question.X1+"', '"+question.X2+"', '"+question.Y1+"', '"+question.Y2+"', '"+question.Radius+"')";
            //SQL.Insert(qry);

            int questionID = dbContext.ImageQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup());
            dbContext.SaveChanges();
            int chartGroupID = dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID;

            Models.DataModels.Question q = new Models.DataModels.Question()
            {
                ChartGroupID   = chartGroupID,
                GameID         = GameID,
                QuestionType   = Models.DataModels.QuestionType.ImageQuestion,
                QuestionTypeID = questionID
            };

            dbContext.Question.Add(q);
            dbContext.SaveChanges();
            //string QuestionID = SQL.Select("SELECT `ID` FROM `imagequestion` WHERE `question` = '"+question.Question+ "' AND `img` = '"+question.img+"'").Last();

            //SQL.Insert("INSERT INTO `chartgroup`(`ID`) VALUES(NULL); INSERT INTO `question` (`ID`, `gameID`, `Type`, `QuestionTypeID`, `ChartGroupID`) VALUES (NULL, '" + GameID.ToString()+"', '0', '"+QuestionID+ "', ( SELECT MAX(`chartgroup`.`ID`) FROM `chartgroup`))");
        }