Пример #1
0
        private void PopulateAssignedSubmissionOfResult(InstructorUser Instructor)
        {
            string SearchString = Instructor.AssignCourse;


            var studentsallCourses = from s in _context.GeneratedStudentCourse
                                     .Include(i => i.ApplicationUser)
                                     .Include(i => i.Course)
                                     .OrderBy(m => m.ApplicationUser.IdentityNumber)
                                     select s;

            if (!String.IsNullOrEmpty(SearchString))
            {
                studentsallCourses = studentsallCourses.Where(s => s.Course.Name.Contains(SearchString));
            }

            var instructorCourses = new HashSet <int>(studentsallCourses.Select(c => c.GeneratedStudentCourseID));

            var viewModel = new List <CarryOverAssigned>();

            foreach (var course in studentsallCourses)
            {
                viewModel.Add(new CarryOverAssigned
                {
                    ApplicationUserName      = course.ApplicationUser.FullName,
                    GeneratedStudentCourseID = course.GeneratedStudentCourseID,
                    Grade = course.Grade,
                    ApplicationUserIdentityNumber = course.ApplicationUser.IdentityNumber,
                    Assigned = instructorCourses.Contains(course.GeneratedStudentCourseID)
                });
            }

            ViewData["Courses"] = viewModel;
        }
Пример #2
0
        public async Task <IActionResult> ViewCoursesAssign(InstructorUser userdetails)
        {
            var user = await GetCurrentUserAsync();


            user.AssignCourse = userdetails.AssignCourse;

            var InstructorUser = await _userManager.Users
                                 .Include(i => i.Department)
                                 .Include(i => i.InstructorCourse)
                                 .ThenInclude(e => e.Course)
                                 .SingleOrDefaultAsync(m => m.Id == user.Id);

            var result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(RedirectToAction("CoursesAssignScore", "Instructors"));
            }

            return(View(InstructorUser));
        }
Пример #3
0
        private void UpdateStudentCourse(string[] selectedCourses, InstructorUser ApplicationUser)
        {
            if (selectedCourses == null)
            {
                ApplicationUser.InstructorCourse = new List <InstructorCourse>();
                return;
            }


            var selectedCoursesHS = new HashSet <string>(selectedCourses);
            var StudentCourses    = new HashSet <int>
                                        (ApplicationUser.InstructorCourse.Select(c => c.Course.CourseID));


            foreach (var course in _context.Course)
            {
                if (selectedCoursesHS.Contains(course.CourseID.ToString()))
                {
                    if (!StudentCourses.Contains(course.CourseID))
                    {
                        ApplicationUser.InstructorCourse.Add(new InstructorCourse
                        {
                            CourseID         = course.CourseID,
                            InstructorUserId = ApplicationUser.Id,
                        });
                    }
                }
                else
                {
                    if (StudentCourses.Contains(course.CourseID))
                    {
                        InstructorCourse courseToRemove = ApplicationUser.InstructorCourse.SingleOrDefault(i => i.CourseID ==
                                                                                                           course.CourseID);
                        _Instructorcontext.Remove(courseToRemove);
                    }
                }
            }
        }
Пример #4
0
        private void PopulateAssignedCourseData(InstructorUser Student)
        {
            var allCourses = _context.Course.Include(m => m.Department);



            var instructorCourses = new HashSet <int>(Student.InstructorCourse.Select(c => c.Course.CourseID));
            var viewModel         = new List <AssignedCourseData>();

            foreach (var course in allCourses)
            {
                viewModel.Add(new AssignedCourseData
                {
                    CourseID    = course.CourseID,
                    Names       = course.Name,
                    CourseCode  = course.CourseCode,
                    Departments = course.Department.Name,
                    Assigned    = instructorCourses.Contains(course.CourseID)
                });
            }

            ViewData["Courses"] = viewModel;
        }
Пример #5
0
        public async Task <IActionResult> Register(RegisterInstructorViewModel model, IFormFile ProfilePictureFile, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;
            if (ModelState.IsValid)
            {
                if (ProfilePictureFile != null)
                {
                    var fnm      = model.IdentityNumber;
                    var filename = fnm + DateTime.Now.ToString("MMddHHmmss") + ".jpg";

                    string uploadPath = Path.Combine(_environment.WebRootPath, "images/Instructor/");

                    if (filename.Contains('\\'))
                    {
                        filename = filename.Split('\\').Last();
                    }

                    using (FileStream fs = new FileStream(Path.Combine(uploadPath, filename), FileMode.Append))
                    {
                        await ProfilePictureFile.CopyToAsync(fs);
                    }

                    model.AvatarImage = filename;
                }


                var user = new InstructorUser

                {
                    UserName       = model.IdentityNumber,
                    Email          = model.Email,
                    IdentityNumber = model.IdentityNumber,
                    Surname        = model.Surname,
                    FirstName      = model.FirstName,
                    MiddleName     = model.MiddleName,
                    FullName       = model.FullName,
                    Gender         = model.Gender,
                    DateofBirth    = model.DateofBirth,
                    State          = model.State,
                    Address        = model.Address,
                    ParentName     = model.ParentName,
                    ParentAddress  = model.ParentAddress,
                    Image          = model.AvatarImage,
                    DepartmentID   = model.DepartmentID,
                };
                var result = await _userManager.CreateAsync(user, model.Surname);

                if (result.Succeeded)
                {
                    //await _userManager.AddToRolesAsync(user, new[] { "Instructor" });
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.Action(nameof(ConfirmEmail), "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    //await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                    //    $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>");
                    await _signInManager.SignInAsync(user, isPersistent : false);

                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #6
0
        private void UpdateSubmissionOfResult(string[] selectedCourses, InstructorUser ApplicationUser)
        {
            if (selectedCourses == null)
            {
                ApplicationUser.CarryOverStudentCourse = new List <CarryOverStudentCourse>();
                return;
            }


            var selectedCoursesHS = new HashSet <string>(selectedCourses);
            var StudentCourses    = new HashSet <string>
                                        (ApplicationUser.CarryOverStudentCourse.Select(c => c.ApplicationIdCourseName));



            foreach (var course in _context.GeneratedStudentCourse.Include(c => c.Semester))
            {
                if (selectedCoursesHS.Contains(course.GeneratedStudentCourseID.ToString()))
                {
                    if (!StudentCourses.Contains(course.ApplicationIdCourseId))
                    {
                        ApplicationUser.CarryOverStudentCourse.Add(new CarryOverStudentCourse
                        {
                            InstructorUserId           = ApplicationUser.Id,
                            ApplicationUserId          = course.ApplicationUserId,
                            CourseID                   = course.CourseID,
                            EntryYearID                = course.EntryYearID,
                            SemesterID                 = course.SemesterID,
                            FullName                   = course.FullName,
                            Grade                      = course.Grade,
                            ApplicationIdSemesterGrade = course.ApplicationUserId + course.Semester.Name + course.Grade,
                            ApplicationIdCourseName    = course.ApplicationIdCourseId
                        });
                    }
                }
                else
                {
                    if (StudentCourses.Contains(course.ApplicationIdCourseId))
                    {
                        CarryOverStudentCourse courseToRemove = _context.CarryOverStudentCourse
                                                                .Include(a => a.Semester)
                                                                .Include(a => a.EntryYear)
                                                                .Include(a => a.ApplicationUser)
                                                                .Include(a => a.Course)
                                                                .Where(a => a.ApplicationIdCourseName.Equals(course.ApplicationIdCourseId)).FirstOrDefault();
                        _context.Remove(courseToRemove);

                        //DeleteConfirmed(course.ApplicationIdCourseId);


                        //var c = _context.CarryOverStudentCourse
                        //    .Include(a => a.Semester)
                        //    .Include(a => a.EntryYear)
                        //    .Include(a => a.ApplicationUser)
                        //    .Include(a => a.Course)
                        //    .Where(a => a.ApplicationIdCourseName.Equals(course.ApplicationIdCourseId)).FirstOrDefault();

                        //if (c != null)
                        //{



                        //    c.Grade = course.Grade;
                        //}


                        // _context.SaveChanges();
                    }



                    //CarryOverStudentCourse courseToRemove = ApplicationUser.CarryOverStudentCourse.SingleOrDefault(i => i.ApplicationIdCourseName ==
                    //    course.ApplicationIdCourseId);
                    //_context.Remove(courseToRemove);

                    //DeleteConfirmed(course.ApplicationIdCourseId);
                }
            }
        }