Beispiel #1
0
        /// <summary>
        /// 数据访问通过条件查询并分页排序
        /// </summary>
        /// <param name="WhereString">查询条件</param>
        /// <param name="PageIndex">当前页码</param>
        /// <param name="PageSize">页大小(每页显示多少条数据)</param>
        /// <param name="OrderString">排序条件(排序条件为必须参数)</param>
        /// <returns>ExamUser实体类对象</returns>
        public List <ExamUser> SelectByWhereAndPage(string WhereString, int PageIndex, int PageSize, string OrderString, out int TotalCount)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@where", WhereString),
                new SqlParameter("@pageIndex", PageIndex),
                new SqlParameter("@pageSize", PageSize),
                new SqlParameter("@orderString", OrderString),
                new SqlParameter("@TotalCount", ParameterDirection.Output)
            };
            List <ExamUser> list  = new List <ExamUser>();
            ExamUser        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("ExamUser_SelectByWhereAndPage", param))
            {
                while (dr.Read())
                {
                    model            = new ExamUser();
                    model.ExamUserId = Convert.ToInt32(dr["ExamUserId"]);
                    model.ExamId     = Convert.ToInt32(dr["ExamId"]);
                    model.UserId     = Convert.ToInt32(dr["UserId"]);
                    model.IsDelete   = Convert.ToBoolean(dr["IsDelete"]);
                    list.Add(model);
                }
                if (dr.NextResult() && dr.Read())
                {
                    TotalCount = Convert.ToInt32(dr["TotalCount"]);
                }
                else
                {
                    TotalCount = 0;
                }
            }
            return(list);
        }
Beispiel #2
0
        public async Task <IActionResult> Finish()
        {
            if (_signInManager.IsSignedIn(User))
            {
                int      a         = 0;
                ExamUser examTaker = await _userManager.GetUserAsync(HttpContext.User);

                examTaker.TestTaker = await _intellectDbContext.TestTakers.FirstOrDefaultAsync();

                Exam exam = await _intellectDbContext.Exams.Where(e => e.Id == exam_id).SingleOrDefaultAsync();

                foreach (Question question in exam.Questions)
                {
                    a = a += question.Score;
                }
                //  examTaker.TestTaker.Result = result;
                await _intellectDbContext.SaveChangesAsync();

                return(RedirectToAction(nameof(Privacy)));
            }
            else
            {
                return(RedirectToAction(nameof(Index)));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> GetProfile()
        {
            ExamUser examUser = new ExamUser();

            examUser.TestTaker = await _intellectDbContext.TestTakers.LastOrDefaultAsync();

            return(View(examUser));
        }
Beispiel #4
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="ExamUser">ExamUser实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Add(ExamUser model)
 {
     SqlParameter[] param = new SqlParameter[]
     {
         new SqlParameter("@ExamId", model.ExamId),
         new SqlParameter("@UserId", model.UserId),
         new SqlParameter("@IsDelete", model.IsDelete)
     };
     return(DBHelper.ExecuteNonQuery("ExamUser_Add", param));
 }
Beispiel #5
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="ExamUser">ExamUser实体对象</param>
 /// <returns>int值,返回自增ID</returns>
 public int AddReturnId(ExamUser model)
 {
     SqlParameter[] param = new SqlParameter[]
     {
         new SqlParameter("@ExamId", model.ExamId),
         new SqlParameter("@UserId", model.UserId),
         new SqlParameter("@IsDelete", model.IsDelete)
     };
     return(Convert.ToInt32(DBHelper.ExecuteScalar("ExamUser_AddReturnId", param)));
 }
Beispiel #6
0
        /// <summary>
        /// 查看全部
        /// </summary>
        /// <returns>list集合</returns>
        public List <ExamUser> SelectAll()
        {
            List <ExamUser> list  = new List <ExamUser>();
            ExamUser        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("ExamUser_SelectAll", null))
            {
                while (dr.Read())
                {
                    model            = new ExamUser();
                    model.ExamUserId = Convert.ToInt32(dr["ExamUserId"]);
                    model.ExamId     = Convert.ToInt32(dr["ExamId"]);
                    model.UserId     = Convert.ToInt32(dr["UserId"]);
                    model.IsDelete   = Convert.ToBoolean(dr["IsDelete"]);
                    list.Add(model);
                }
            }
            return(list);
        }
Beispiel #7
0
        public async Task <IActionResult> AdminRegister(RegisterModel registerModel)
        {
            if (ModelState.IsValid)
            {
                ExamUser examUser = await _userManager.FindByEmailAsync(registerModel.Email);

                if (examUser != null)
                {
                    ModelState.AddModelError("", "This user already exists");
                }
                else
                {
                    examUser = new ExamUser
                    {
                        Email    = registerModel.Email,
                        UserName = registerModel.UserName
                    };

                    if (registerModel.Password == registerModel.ConfirmPassword)
                    {
                        IdentityResult AdminResult = await _userManager.CreateAsync(examUser, registerModel.Password);

                        if (AdminResult.Succeeded)
                        {
                            IdentityResult result = await _userManager.AddToRoleAsync(examUser, RoleType.Admin.ToString());

                            if (result.Succeeded)
                            {
                                await _signInManager.SignInAsync(examUser, isPersistent : false);

                                return(RedirectToAction(nameof(AdminController.Admin), "Admin"));
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Confirm password is different");
                    }
                }
            }
            return(View(registerModel));
        }
Beispiel #8
0
        /// <summary>
        /// 通过Id查询
        /// </summary>
        /// <param name="Id">主键Id</param>
        /// <returns>ExamUser实体类对象</returns>
        public ExamUser SelectById(int Id)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@ExamUserId", Id)
            };
            ExamUser model = new ExamUser();

            using (SqlDataReader dr = DBHelper.RunProcedure("ExamUser_SelectById", param))
            {
                if (dr.Read())
                {
                    model.ExamUserId = Convert.ToInt32(dr["ExamUserId"]);
                    model.ExamId     = Convert.ToInt32(dr["ExamId"]);
                    model.UserId     = Convert.ToInt32(dr["UserId"]);
                    model.IsDelete   = Convert.ToBoolean(dr["IsDelete"]);
                }
            }
            return(model);
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                var user = new ExamUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);


                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Beispiel #10
0
        public async Task <IActionResult> RegisterUser(RegisterModel registermodel, int Id)
        {
            if (ModelState.IsValid)
            {
                registermodel.TestTaker = await _intellectDbContext.TestTakers.SingleOrDefaultAsync(x => x.Id == Id);

                ExamUser appUser = await _userManager.FindByEmailAsync(registermodel.Email);

                if (appUser != null)
                {
                    ModelState.AddModelError("", "Belə istifadəçi artıq mövcuddur");
                }
                else
                {
                    appUser = new ExamUser
                    {
                        UserName    = registermodel.UserName,
                        Email       = registermodel.Email,
                        TestTakerId = registermodel.TestTaker.Id
                    };

                    IdentityResult result = await _userManager.CreateAsync(appUser, registermodel.Password);

                    if (result.Succeeded)
                    {
                        IdentityResult newresult = await _userManager.AddToRoleAsync(appUser, RoleType.User.ToString());

                        if (newresult.Succeeded)
                        {
                            ViewBag.Alert = "Siz uğurla qeydiyyatdan keçdiniz";
                            await _signInManager.SignInAsync(appUser, isPersistent : false);
                        }

                        return(RedirectToAction(nameof(HomeController.Index), "Home"));
                    }
                    AddErrors(result);
                }
            }
            return(View(registermodel));
        }
Beispiel #11
0
        public async Task <IActionResult> LoginUser(LoginModel loginmodel, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            if (ModelState.IsValid)
            {
                ExamUser currentuser = await _userManager.FindByEmailAsync(loginmodel.UserName);

                Microsoft.AspNetCore.Identity.SignInResult signInResult = await _signInManager.PasswordSignInAsync(loginmodel.UserName, loginmodel.Password, loginmodel.RememberMe, lockoutOnFailure : true);

                if (signInResult.Succeeded)
                {
                    var user = this.User;
                    return(RedirectToAction(nameof(Ouruser)));
                }
                else
                {
                    ModelState.AddModelError("", "Username or password is incorrect");
                }
            }

            return(View(loginmodel));
        }
Beispiel #12
0
        /// <summary>
        /// 通过条件查询
        /// </summary>
        /// <param name="WhereString">查询条件</param>
        /// <returns>ExamUser实体类对象</returns>
        public List <ExamUser> SelectByWhere(string WhereString)
        {
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter("@where", WhereString)
            };
            List <ExamUser> list  = new List <ExamUser>();
            ExamUser        model = null;

            using (SqlDataReader dr = DBHelper.RunProcedure("ExamUser_SelectByWhere", param))
            {
                while (dr.Read())
                {
                    model            = new ExamUser();
                    model.ExamUserId = Convert.ToInt32(dr["ExamUserId"]);
                    model.ExamId     = Convert.ToInt32(dr["ExamId"]);
                    model.UserId     = Convert.ToInt32(dr["UserId"]);
                    model.IsDelete   = Convert.ToBoolean(dr["IsDelete"]);
                    list.Add(model);
                }
            }
            return(list);
        }
Beispiel #13
0
        public async Task <IActionResult> Question(int Id, int count, int myanswer)
        {
            AdminViewModel admodel = new AdminViewModel();

            admodel.CurrentQuestion = await _intellectDbContext.Questions.Where(x => x.Id == Id).SingleOrDefaultAsync();

            admodel.Answers = await _intellectDbContext.Answers.Where(y => y.QuestionId == Id).ToListAsync();

            admodel.Equestions = await _intellectDbContext.Questions.Where(q => q.ExamId == exam_id).ToListAsync();

            /*  var date = HttpContext.Session.GetString("currentQuestion_1");
             *
             * return Ok(new
             * {
             *    date,
             *    Id,
             *    HttpContext.Session.Keys
             */
            //  admodel.CurrentQuestion.Remainedtime = new TimeSpan(0, 0, 60);
            //  var interval = DateTime.Now - DateTime.Parse(HttpContext.Session.GetString("currentQuestion_" + Id));

            var sesdata  = HttpContext.Session.GetString("currentQuestion_" + PreviousId);
            var interval = DateTime.Now - DateTime.Parse(sesdata);

            correctAnswer = _intellectDbContext.Answers.Where(a => a.QuestionId == PreviousId && a.Correct == true).SingleOrDefault().Id;

            if (_signInManager.IsSignedIn(User))
            {
                ExamUser examTaker = await _userManager.GetUserAsync(HttpContext.User);

                examTaker.TestTaker = await _intellectDbContext.TestTakers
                                      .Include(tt => tt.UserQuestions)
                                      .Where(t => t.Id == examTaker.TestTakerId)
                                      .FirstOrDefaultAsync();

                admodel.CurrentQuestion = examTaker.TestTaker.UserQuestions.Select(u => u.Question).Where(x => x.Id == Id).SingleOrDefault();

                if (myanswer == correctAnswer)
                {
                    admodel.CurrentQuestion.Score = 60 - (int)interval.TotalMilliseconds / 1000;
                    await _intellectDbContext.SaveChangesAsync();

                    // admodel.CurrentQuestion.Score = result;
                }
            }

            if (count > 1)
            {
                var question = RemainedQuestions.Single(r => r.Id == admodel.CurrentQuestion.Id);
                PreviousId = question.Id;
                RemainedQuestions.Remove(question);
                admodel.NextQuestion = RemainedQuestions[0];
                count -= 1;
            }
            else
            {
                admodel.NextQuestion = RemainedQuestions[0];
                count -= 1;
            }

            if (count == -1)
            {
                return(RedirectToAction(nameof(Finish)));
            }

            ViewBag.Equestions = count;

            return(RedirectToAction(nameof(Question)));
        }
Beispiel #14
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="ExamUser">ExamUser实体对象</param>
 /// <returns>int值,返回自增ID</returns>
 public int AddReturnId(ExamUser model)
 {
     return(dal.AddReturnId(model));
 }
Beispiel #15
0
 /// <summary>
 /// 增加
 /// </summary>
 /// <param name="ExamUser">ExamUser实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Add(ExamUser model)
 {
     return(dal.Add(model));
 }
Beispiel #16
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="ExamUser">ExamUser实体对象</param>
 /// <returns>bool值,判断是否操作成功</returns>
 public bool Change(ExamUser model)
 {
     return(dal.Change(model));
 }
Beispiel #17
0
        public async Task <IActionResult> Question(int Id, int count, int myanswer)
        {
            var currentExam = HttpContext.Session.GetObject <Exam>(Sessions.CurrentExam);

            if (currentExam.ExamDate.Date != DateTime.Now.Date || currentExam.ExamStartDateTime.TimeOfDay > DateTime.Now.TimeOfDay || currentExam.ExamEndDateTime.TimeOfDay < DateTime.Now.TimeOfDay)
            {
                return(RedirectToAction(nameof(Finish)));
            }
            var            sesdata           = HttpContext.Session.GetString(Sessions.CurrentQuestionStartTime);
            var            interval          = DateTime.Now - DateTime.Parse(sesdata);
            AdminViewModel admodel           = new AdminViewModel();
            int            currentExamId     = int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId));
            int            currentQuestionId = int.Parse(HttpContext.Session.GetString(Sessions.CurrentQuestionId));

            admodel.CurrentQuestion = GetQuestions(int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId))).Where(x => x.Id == Id).SingleOrDefault();
            admodel.Answers         = GetAnswers(int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId))).Where(y => y.QuestionId == Id).ToList();
            admodel.Equestions      = GetQuestions(int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId))).Where(q => q.ExamId == currentExamId).ToList();

            /*  var date = HttpContext.Session.GetString("currentQuestion_1");
             *
             * return Ok(new
             * {
             *    date,
             *    Id,
             *    HttpContext.Session.Keys
             */
            //  admodel.CurrentQuestion.Remainedtime = new TimeSpan(0, 0, 60);
            //  var interval = DateTime.Now - DateTime.Parse(HttpContext.Session.GetString("currentQuestion_" + Id));


            correctAnswer = _intellectDbContext.Answers.Where(a => a.QuestionId == PreviousId && a.Correct == true).SingleOrDefault().Id;

            if (_signInManager.IsSignedIn(User))
            {
                ExamUser examTaker = await _userManager.GetUserAsync(HttpContext.User);

                examTaker.TestTaker = await _intellectDbContext.TestTakers
                                      .Include(tt => tt.UserQuestions)
                                      .Where(t => t.Id == examTaker.TestTakerId)
                                      .FirstOrDefaultAsync();

                admodel.CurrentQuestion = GetQuestions(int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId))).FirstOrDefault(x => x.Id == Id);
                var score = 0;
                if (myanswer == correctAnswer && interval.TotalSeconds < 61.5)
                {
                    //admodel.CurrentQuestion.Score = 60 - (int)interval.TotalMilliseconds / 1000;
                    //// admodel.CurrentQuestion.Score = result;
                    score = 60 - (int)interval.TotalMilliseconds / 1000;
                }
                UserQuestion userQuestion = new UserQuestion();
                userQuestion.AnswerId       = myanswer;
                userQuestion.ExamId         = int.Parse(HttpContext.Session.GetString(Sessions.CurrentExamId));
                userQuestion.QuestionId     = int.Parse(HttpContext.Session.GetString(Sessions.CurrentQuestionId));
                userQuestion.Score          = score;
                userQuestion.TestTakerId    = examTaker.TestTakerId;
                userQuestion.TimeOfQuestion = DateTime.Now;
                userQuestion.TimeSpend      = (int)interval.TotalSeconds;
                InsertUserQuestionInSession(userQuestion);
                //await _intellectDbContext.UserQuestions.AddAsync(userQuestion);
                //await _intellectDbContext.SaveChangesAsync();
            }

            if (count == -1)
            {
                return(RedirectToAction(nameof(Finish)));
            }

            if (count > 1)
            {
                var question = RemainedQuestions.Single(r => r.Id == admodel.CurrentQuestion.Id);
                PreviousId = question.Id;
                RemainedQuestions.Remove(question);
                admodel.NextQuestion = RemainedQuestions[0];
            }
            else
            {
                admodel.NextQuestion = RemainedQuestions[0];
                //count -= 1;
            }
            count -= 1;

            ViewBag.Equestions = count;

            return(RedirectToAction(nameof(Question)));
        }