Exemplo n.º 1
0
        public async Task <ActionResult> Enroll(string userName, string idExam)
        {
            var exam = _examRepository.GetExamById(idExam);
            var u    = await _userManager.FindByNameAsync(userName);

            if (u == null)
            {
                return(NotFound("You are not logged in!"));
            }

            var i     = (u.ExamEnrollment.ToArray().Length);
            var model = new EnrollForExamViewModel
            {
                IdExam         = u.ExamEnrollment[i].SubjectCode,
                RoomId         = u.ExamEnrollment[i].RoomId,
                Mark           = u.ExamEnrollment[i].Mark,
                UserName       = u.UserName,
                ProgrammeCode  = u.Programmes.ProgrammeCode,
                StatusMessage  = StatusMessage,
                StatusMessage1 = StatusMessage1
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Enroll(EnrollForExamViewModel model)
        {
            var u = await _userManager.FindByIdAsync(model.UserName);

            var flag_already_reg = 0;

            if (u == null)
            {
                return(NotFound("You are not logged in!"));
            }
            if (u.Programmes.ProgrammeCode != model.ProgrammeCode)
            {
                return(NotFound(StatusMessage = "The program line is not applicable to the user"));
            }
            // if (u.Programmes.ProgrammeCode != model.ProgrammeCode) return Redirect($"/Exam/");
            var date = DateTime.Now;
            var i    = (u.ExamEnrollment.ToArray().Length) - 1; // it saved over the last element in the array

            if (i > -1)
            {
                for (int wow = 0; wow < i + 1; wow++)
                {
                    if (u.ExamEnrollment.ElementAtOrDefault(wow).SubjectCode == model.IdExam)
                    {
                        //return Window.Confirm(); install package
                        //MessageBox.Show
                        StatusMessage    = " You are already previously enrolled to the selected exam.";
                        flag_already_reg = 1;
                    }
                }
            }
            if (flag_already_reg == 0)
            {
                //if (model.ExamDate < DateTime.Now) return NotFound(StatusMessage = "The exam date is " + model.ExamDate + " But the date today is " + date + " so  The Registration time is passed, you can not enroll now!");

                var temp = new StudentExamEnrollmentArrayViewModel();

                temp.SubjectCode = model.IdExam;
                temp.RoomId      = model.RoomId;
                temp.Mark        = model.Mark;

                u.ExamEnrollment.Add(temp);
                //u.ExamEnrollment.ElementAtOrDefault(i).SubjectCode = model.IdExam;
                //u.ExamEnrollment.ElementAtOrDefault(i).RoomId = model.RoomId;
                //u.ExamEnrollment.ElementAtOrDefault(i).Mark = model.Mark;

                //u.ExamEnrollment[i].SubjectCode = model.IdExam;
                //u.ExamEnrollment[i].RoomId = model.RoomId;
                //u.ExamEnrollment[i].Mark = model.Mark;

                //set a new repository
                //after making the method,
                await _userManager.UpdateAsync(u); // this will update the Array replacing the last element in the array

                //    await _userUserCollection.InsertOneAsync(u);
                // _examRepository.Enroll.InsertMany(u);
                //put code here
                //potential solution: await _EntityDomainManager<TData>.InsertAsync(u);
                //public override System.Threading.Tasks.Task<TData> InsertAsync (TData data);

                StatusMessage    = "You are now enrolled to the exam.";
                flag_already_reg = 0;
            }
            return(Redirect("/Exam"));
        }