Exemple #1
0
        public TakeTestModel GetTest(int numQuestions, QuizzModel quizz)
        {
            TakeTestModel test = null;

            _numQuestions = numQuestions;
            _quizz        = quizz;

            switch (_quizz.MainType)
            {
            case 0:
                test = HourGetTest();
                break;

            case 1:
                test = HalfHourGetTest();
                break;

            case 2:
                test = QuarterHourGetTest();
                break;

            case 3:
                test = FiveMinutesGetTest();
                break;

            case 4:
                test = MinutesGetTest();
                break;
            }

            return(test);
        }
        public QuizzModel GetQuizzById(int id)
        {
            try
            {
                QuizzModel model  = null;
                var        entity = _uow.Quizzes.GetAll()
                                    .Include(q => q.Tests)
                                    .Include(q => q.Reviewers)
                                    .Where(q => q.Id == id && q.IsDeleted == false)
                                    .FirstOrDefault();

                if (entity != null)
                {
                    model = MappingUtil.Map <Quizz, QuizzModel>(entity);
                }
                model.ReviewerId = entity.Reviewers.FirstOrDefault().Id;
                model.TestId     = entity.Reviewers.FirstOrDefault().Id;

                return(model);
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(null);
            }
        }
Exemple #3
0
        public TakeTestModel GetTest(int numQuestions, QuizzModel quizz)
        {
            TakeTestModel test = null;

            _numQuestions = numQuestions;
            _quizz        = quizz;

            switch (_quizz.MainType)
            {
            case 0:
                test = AdditionGetTest();
                break;

            case 1:
                test = SubtractionGetTest();
                break;

            case 2:
                test = MultiplicationGetTest();
                break;

            case 3:
                test = DivisionGetTest();
                break;
            }

            return(test);
        }
        // PATCH: api/Quizz/5
        public HttpResponseMessage Patch([FromBody] QuizzModel model)
        {
            try
            {
                if (ModelState.IsValid == false || _quizzSvc.UpdateQuizz(model) == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ServiceException ex)
            {
                return(Request.CreateResponse(ex.HttpStatusCode, ex.Message));
            }
        }
        public bool UpdateQuizz(QuizzModel model)
        {
            try
            {
                var entity = MappingUtil.Map <QuizzModel, Quizz>(model);

                _uow.Quizzes.Update(entity);
                _uow.SaveChanges();
            }
            catch (Exception ex)
            {
                _svcContainer.LoggingSvc.Log(ex);
                return(false);
            }

            return(true);
        }
        public bool CreateQuizz(QuizzModel model)
        {
            var entity = MappingUtil.Map <QuizzModel, Quizz>(model);

            entity.OwnerId    = _currentUser.Id;
            entity.QuizRating = new QuizzRating();
            entity.Tests.Add(new Test
            {
                DefaultSetting = new TestSetting()
            });
            entity.Reviewers.Add(new Reviewer());

            _uow.Quizzes.Add(entity);
            _uow.SaveChanges();

            MappingUtil.Map <Quizz, QuizzModel>(entity, model);

            _notificationSvc.DepQuizzNotificationSvc.AddDepQuizzSubmitNotification(model.Id);
            _activitySvc.QuizzActivitySvc.AddQuizzCreateActivity(model.Id);
            return(true);
        }
Exemple #7
0
        public QuizzController(ITokenizer tokenizer)
        {
            Post["/newquizz/"] = x =>
            {
                //this.RequiresAuthentication();
                var quizzData  = ParseRequestData(Request.Body);
                var quizzModel = new QuizzModel();
                quizzModel.CreateNewQuizz(quizzData);
                return(HttpStatusCode.OK);
            };

            Get["/singlequizz/{id}"] = x =>
            {
                var id         = int.Parse(x["id"].Value);
                var quizzModel = new QuizzModel();
                var response   = (Response)quizzModel.GetQuizz(id);
                response.ContentType = "application/json";
                response.StatusCode  = HttpStatusCode.OK;
                return(response);
            };

            Get["/allquizzes/"] = x =>
            {
                //this.RequiresAuthentication();
                var quizzModel = new QuizzModel();
                var response   = (Response)quizzModel.GetAllQuizzes();
                response.ContentType = "application/json";
                response.StatusCode  = HttpStatusCode.OK;
                return(response);
            };

            Post["/addquestions/"] = x =>
            {
                var quizzData  = ParseRequestData(Request.Body);
                var quizzModel = new QuizzModel();

                return(HttpStatusCode.OK);
            };
        }
 public SubtractionQuestionsCreator(QuizzModel quizz)
 {
     _quizz = quizz;
     _takeTestModelCreator = new TakeTestModelCreator();
     _random = new Random();
 }