Example #1
0
        public ActionResult LogOn(admindetails model, string returnUrl)
        {
            OnlineExamEntities4 db = new OnlineExamEntities4();

            if (ModelState.IsValid)
            {
                var admin = (from adminlist in db.Admins
                             where adminlist.Name == model.UserName && adminlist.Password == model.Password
                             select new
                {
                    adminlist.Name
                }).ToList();

                if (admin.FirstOrDefault() != null)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                    return(RedirectToAction("Details", "Admin"));
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login credentials.");
                }
            }
            return(View());
        }
Example #2
0
        public ActionResult EditTest(SessionModel model)
        {
            if (model != null)
            {
                var _ctx = new OnlineExamEntities4();
                var test = _ctx.Tests.Where(x => x.Id == model.TestId).FirstOrDefault();
                if (test != null)
                {
                    ViewBag.TestId          = test.Id;
                    ViewBag.TestName        = test.Name;
                    ViewBag.TestDescription = test.Description;
                    ViewBag.QuestionCount   = test.TestXQuestions.Count;
                    ViewBag.TestDuration    = test.DurationInMinute;
                    var sum = 0;
                    var mm  = test.TestXQuestions.Where(x => x.TestId == test.Id).ToList();
                    foreach (var m in mm)
                    {
                        sum = sum + m.Question.Points;
                    }
                    ViewBag.MM = sum;
                }
                var ques = _ctx.Questions.ToList();
                IList <Question> testxquestion = (
                    from a in _ctx.TestXQuestions.Where(x => x.TestId == test.Id).AsEnumerable()
                    join b in ques on a.QuestionId equals b.Id
                    select b).ToList();

                return(View(testxquestion));
            }
            return(View(model));
        }
Example #3
0
 public ActionResult Instruction(SessionModel model)
 {
     if (model != null)
     {
         var _ctx = new OnlineExamEntities4();
         var test = _ctx.Tests.Where(x => x.IsActive == true && x.Id == model.TestId).FirstOrDefault();
         if (test != null)
         {
             ViewBag.TestName        = test.Name;
             ViewBag.TestDescription = test.Description;
             ViewBag.QuestionCount   = test.TestXQuestions.Count;
             ViewBag.TestDuration    = test.DurationInMinute;
         }
     }
     return(View(model));
 }
Example #4
0
        public ActionResult Index()
        {
            var _ctx = new OnlineExamEntities4();

            ViewBag.Tests = _ctx.Tests.Where(x => x.IsActive == true).Select(x => new { x.Id, x.Name }).ToList();
            SessionModel _model = null;

            if (Session["SessionModel"] == null)
            {
                _model = new SessionModel();
            }
            else
            {
                _model = (SessionModel)Session["SessionModel"];
            }

            return(View(_model));
        }
Example #5
0
        public ActionResult Result(Guid token, ResultModel model)
        {
            var _ctx = new OnlineExamEntities4();
            // verify the user is registered and is allowed to check the question
            Registration registration = _ctx.Registrations.Where(x => x.Token == token
                                                                 ).Single();

            if (token == null)
            {
                TempData["message"] = "this registration is invalid";
                return(RedirectToAction("Index"));
            }
            else
            {
                registration.TokenExpireTime = DateTime.Now.TimeOfDay;
                _ctx.SaveChanges();
            }

            var test = _ctx.TestXPapers.Where(x => x.RegistrationId == registration.Id).FirstOrDefault();

            if (test != null)
            {
                model.TestId   = registration.TestId;
                model.TestName = registration.Test.Name;
                model.UserName = registration.User.Name;
                decimal msum = 0, qsum = 0;
                var     mlist = _ctx.TestXPapers.Where(x => x.RegistrationId == registration.Id && x.MarkScored > 0).Select(x => x.MarkScored).ToList();
                foreach (var m in mlist)
                {
                    msum = msum + m.Value;
                }
                var markscored = msum;
                var qlist      = _ctx.TestXQuestions.Where(x => x.TestId == registration.TestId).Select(x => x.Question.Points).ToList();
                foreach (var q in qlist)
                {
                    qsum = qsum + q;
                }
                //ViewBag.totalmarks = 2*(_ctx.Tests.Where(x => x.Id == registration.TestId).Select(x=>x.TestXQuestions.Count()).FirstOrDefault());
                ViewBag.totalmarks = qsum;
                //model.MarkScored = markscored;
                model.MarkScored          = msum;
                registration.MarkScored   = markscored;
                registration.MaximumMarks = ViewBag.totalmarks;
                _ctx.SaveChanges();

                // to remove textxpapers data after the test
                Registration reg = _ctx.Registrations.Where(x => x.Token == token
                                                            ).SingleOrDefault();
                var txp = _ctx.TestXPapers.Where(x => x.RegistrationId == registration.Id).ToList();
                if (token == null)
                {
                    TempData["message"] = "this registration is invalid";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    foreach (var t in txp)
                    {
                        _ctx.TestXPapers.Remove(t);
                    }
                    //_ctx.Registrations.Remove(registration); we don't want to remove registration
                    _ctx.SaveChanges();
                }


                // to send the marks scored by user to his/her email
                sendResultMail(registration);
            }

            return(View(model));
        }
Example #6
0
        public ActionResult PostAnswer(AnswerModel choices)
        {
            var _ctx = new OnlineExamEntities4();
            // verify the user is registered and is allowed to check the question
            var registration = _ctx.Registrations.Where(x => x.Token == (choices.Token)).FirstOrDefault();

            if (registration == null)
            {
                TempData["message"] = "this token is invalid";
                return(RedirectToAction("Index"));
            }
            if (registration.TokenExpireTime < DateTime.Now.TimeOfDay)
            {
                TempData["message"] = "the exam duration has expired at" + registration.TokenExpireTime.ToString();
                //_ctx.Registrations.Remove(registration);
                //_ctx.SaveChanges();
                return(RedirectToAction("Index"));
            }

            // to check the answered question is answered or not . If answered then store them in database and evaluate the marks scored.

            var testQuestionInfo = _ctx.TestXQuestions.Where(x => x.TestId == registration.TestId &&
                                                             x.QuestionNumber == choices.QuestionId)
                                   .Select(x => new { TQId  = x.Id,
                                                      QT    = x.Question.QuestionType,
                                                      QID   = x.Id,
                                                      POINT = (decimal)x.Question.Points }).FirstOrDefault();

            if (testQuestionInfo != null)
            {
                if (choices.UserChoices.Count() > 0) // if choices is of radio or checkbox type
                {
                    var c                      = choices.UserSelectedId.ToList();
                    var quesid                 = (c.Count() != 0)? _ctx.Choices.Where(x => x.QuestionId == testQuestionInfo.TQId).Select(x => x.QuestionId).FirstOrDefault() : 0;
                    var testxpaperlist         = _ctx.TestXPapers.Where(x => x.RegistrationId == registration.Id && x.TestXQuestionId == quesid).FirstOrDefault();
                    var allPointValueOfChoices =
                        (
                            from a in _ctx.Choices.Where(x => x.IsActive).AsEnumerable()
                            join b in c on a.Id equals b.ChoiceId
                            select new { a.Id, Point = (decimal)a.Points }).AsEnumerable()
                        .Select(x => new TestXPaper()
                    {
                        RegistrationId  = registration.Id,
                        TestXQuestionId = testQuestionInfo.QID,
                        ChoiceId        = x.Id,
                        Answer          = "checked",
                        MarkScored      = Math.Floor((decimal)_ctx.Choices.Where(y => y.Id == x.Id && y.Points > 0).Select(p => p.Question.Points).FirstOrDefault()) // getting the points of the question for correct answer
                    }).ToList();


                    if (testxpaperlist != null) //&& testxpaperlist.RegistrationId == registration.Id && testxpaperlist.TestXQuestionId == testQuestionInfo.QID)
                    {
                        testxpaperlist.ChoiceId   = allPointValueOfChoices[0].ChoiceId;
                        testxpaperlist.Answer     = allPointValueOfChoices[0].Answer;
                        testxpaperlist.MarkScored = allPointValueOfChoices[0].MarkScored;
                    }
                    else
                    {
                        if (c.Count != 0)
                        {
                            _ctx.TestXPapers.Add(allPointValueOfChoices[0]);
                        }
                    }
                    _ctx.SaveChanges();
                }
                else
                {
                    //answer of the type text
                    _ctx.TestXPapers.Add(new TestXPaper()
                    {
                        RegistrationId  = registration.Id,
                        TestXQuestionId = testQuestionInfo.QID,
                        ChoiceId        = choices.UserChoices.FirstOrDefault().ChoiceId,
                        MarkScored      = 2,
                        Answer          = choices.Answer
                    });
                }
                _ctx.SaveChanges();
            }
            //get the next question depending on the direction
            var nextQuestionNumber = 1;

            if (choices.Direction.Equals("forward", StringComparison.CurrentCultureIgnoreCase))
            {
                nextQuestionNumber = _ctx.TestXQuestions.Where(x => x.TestId == choices.TestId &&
                                                               x.QuestionNumber > choices.QuestionId)
                                     .OrderBy(x => x.QuestionNumber).Take(1).Select(x => x.QuestionNumber).FirstOrDefault();
            }

            else

            {
                nextQuestionNumber = _ctx.TestXQuestions.Where(x => x.TestId == choices.TestId &&
                                                               x.QuestionNumber < choices.QuestionId)
                                     .OrderByDescending(x => x.QuestionNumber).Take(1).Select(x => x.QuestionNumber).FirstOrDefault();
            }
            if (nextQuestionNumber < 1)
            {
                nextQuestionNumber = 1;
            }


            return(RedirectToAction("EvalPage", new {
                @token = Session["TOKEN"],
                @qno = nextQuestionNumber
            }));
        }
Example #7
0
        public ActionResult EvalPage(Guid token, int?qno)
        {
            if (token == null)
            {
                TempData["message"] = "you have an invalid token. Please re-register and try again";
                return(RedirectToAction("Index"));
            }
            var _ctx = new OnlineExamEntities4();
            // verify the user is registered and is allowed to check the question
            var registration = _ctx.Registrations.Where(x => x.Token == (token)).FirstOrDefault();

            if (registration == null)
            {
                TempData["message"] = "this registration is invalid";
                return(RedirectToAction("Index"));
            }
            if (registration.TokenExpireTime < DateTime.Now.TimeOfDay)
            {
                TempData["message"] = "the exam duration has expired at " + registration.TokenExpireTime.ToString();
                //_ctx.Registrations.Remove(registration);
                //_ctx.SaveChanges();
                return(RedirectToAction("Result", new { @token = Session["TOKEN"] }));
            }
            if (qno.GetValueOrDefault() < 1)
            {
                qno = 1;
            }
            var testQuestionId = _ctx.TestXQuestions
                                 .Where(x => x.TestId == registration.TestId && x.QuestionNumber == qno)
                                 .Select(x => x.Id).FirstOrDefault();


            if (testQuestionId > 0)
            {
                var _model = _ctx.TestXQuestions.ToList().Where(x => x.Id == testQuestionId)
                             .Select(x => new QuestionModel()
                {
                    QuestionType   = x.Question.QuestionType,
                    QuestionNumber = x.QuestionNumber,
                    Question       = x.Question.Question1,
                    Point          = x.Question.Points,
                    TestId         = x.TestId,
                    TestName       = x.Test.Name,
                    Options        = x.Question.Choices.Where(y => y.IsActive == true).Select(y => new QXOModel()
                    {
                        ChoiceId = y.Id,
                        Label    = y.Label
                    }).ToList(),
                }).FirstOrDefault();

                // now if it is already answered earlier, set the choice of the user

                var savedAnswers = _ctx.TestXPapers.Where(x => x.TestXQuestionId == testQuestionId && x.RegistrationId == registration.Id && x.Choice.IsActive == true)
                                   .Select(x => new { x.ChoiceId, x.Answer }).ToList();

                foreach (var savedAnwer in savedAnswers)
                {
                    _model.Options.Where(x => x.ChoiceId == savedAnwer.ChoiceId).FirstOrDefault().Answer = savedAnwer.Answer;
                }

                _model.TotalQuestionInSet = _ctx.TestXQuestions.Where(x => x.Question.IsActive == true && x.TestId == registration.TestId).Count();
                ViewBag.TimeExpire        = (registration.TokenExpireTime);
                return(View(_model));
            }
            else
            {
                return(View("Error"));
            }
        }
Example #8
0
        public ActionResult Registration(SessionModel model)
        {
            if (model != null)
            {
                Session["SessionModel"] = model;
            }
            if (model == null || string.IsNullOrEmpty(model.UserName) || string.IsNullOrEmpty(model.Email)
                // || string.IsNullOrEmpty(model.Password)
                || model.TestId < 1)
            {
                TempData["message"] = "Invalid Registration Details. Please try again.";
                return(RedirectToAction("Index"));
            }
            var _ctx = new OnlineExamEntities4();
            //to register the user to system
            //to register the user for test
            User _user = _ctx.Users.Where(x => x.Name.Equals(model.UserName, StringComparison.InvariantCultureIgnoreCase) &&
                                          ((string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(x.Email)) || (x.Email == model.Email))
                                          //&& ((string.IsNullOrEmpty(model.Password) && string.IsNullOrEmpty(x.Password)) || (x.Password == model.Password))
                                          ).FirstOrDefault();

            if (_user == null)
            {
                _user = new User()
                {
                    Name  = model.UserName,
                    Email = model.Email,
                    //Password = model.Password,
                    EntryDate   = DateTime.Now,
                    AccessLevel = "user",
                    IsValid     = true
                };
                _ctx.Users.Add(_user);
                _ctx.SaveChanges();
            }
            var          time         = DateTime.Now.TimeOfDay;
            Registration registration = _ctx.Registrations.Where(x => x.UserId == _user.Id &&
                                                                 x.TestId == model.TestId &&
                                                                 x.TokenExpireTime > time
                                                                 ).FirstOrDefault();

            if (registration != null)
            {
                this.Session["TOKEN"] = registration.Token;
                //this.Session["TOKENEXPIRE"] = registration.TokenExpireTime;
            }
            else
            {
                Test test = _ctx.Tests.Where(x => x.IsActive == true && x.Id == model.TestId).FirstOrDefault();
                if (test != null)
                {
                    Registration newRegistration = new Registration()
                    {
                        RegistrationDate = DateTime.Now,
                        TestId           = model.TestId,
                        Token            = Guid.NewGuid(),
                        TokenExpireTime  = time + test.DurationInMinute // add time test.DurationInMinute to current time
                    };
                    _user.Registrations.Add(newRegistration);
                    _ctx.Registrations.Add(newRegistration);
                    _ctx.SaveChanges();
                    this.Session["TOKEN"] = newRegistration.Token;
                    // this.Session["TOKENEXPIRE"] = newRegistration.TokenExpireTime;
                }
            }


            return(RedirectToAction("EvalPage", new { @token = Session["TOKEN"] }));
        }