public async Task <IActionResult> Create([Bind("ProgrammeID,ProgrammeName,ProgrammeDescription,ProgrammeQQILevel,ProgrammeCredits,ProgrammeCost")] Programme programme)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await programmeRepository.AddAsync(programme);

                    await programmeRepository.SaveChangesAsync();

                    ViewBag.SuccessMsg = "Programme Created Successfully";

                    var programmeDetails = await programmeRepository.FindByIdAsync(programme.ProgrammeID);

                    ModelState.Clear();

                    return(RedirectToAction("Details", new { id = programme.ProgrammeID }));
                }
                return(View(programme));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Create(Module module)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await moduleRepository.AddAsync(module);

                    await moduleRepository.SaveChangesAsync();

                    ViewBag.SuccessMsg = "Module Created Successfully";

                    ModelState.Clear();

                    return(RedirectToAction("Details", new { id = module.ModuleID }));
                }
                return(View(module));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        [HttpGet] // GET: Teacher/Delete/5
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                if (id == null)
                {
                    return(RedirectToAction("NotFoundPage", "Error"));
                }

                var teacher = await teacherRepository.FindByIdIncludeProgrammeAsync(id);

                if (teacher == null)
                {
                    return(RedirectToAction("NotFoundPage", "Error"));
                }
                return(View(teacher));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Edit(string id,
                                               [Bind("StudentID,FirstName,SurName,Password,AddressOne,AddressTwo,Town,County,MobilePhoneNumber,EmailAddress,EmergencyMobilePhoneNumber,StudentPPS,ProgrammeFeePaid,DateOfBirth,GenderType,FullOrPartTime,StudentImage,ProgrammeID")] Student student)
        {
            if (id != student.StudentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    studentRepository.Update(student);
                    await studentRepository.SaveChangesAsync();

                    return(RedirectToAction("Details", new { id = student.StudentID }));
                }
                catch (DataAccessException e)
                {
                    if (!await StudentExists(student.StudentID))
                    {
                        return(NotFound());
                    }
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
            }
            return(View(student));
        }
        // GET: Student/Delete/5
        public async Task <IActionResult> Delete(string id)
        {
            try
            {
                if (id == null)
                {
                    ViewBag.ErrorMsg = $"Invalid student ID: {id}";
                    return(RedirectToAction("Unknown", "Error"));
                }

                var student = await studentRepository.FindByIdAsync(id);

                if (student == null)
                {
                    ViewBag.ErrorMsg = $"Could not find student: {id}";
                    return(RedirectToAction("Unknown", "Error"));
                }

                return(View(student));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
Пример #6
0
        public async Task <IActionResult> Create(Assessment assessment)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    await assessmentRepository.AddAsync(assessment);

                    await assessmentRepository.SaveChangesAsync();

                    ViewBag.SuccessMsg = "Assessment Created Successfully";
                    ViewBag.ModuleList = await moduleRepository.AllAsync();

                    ViewBag.AssessmentID = await GetAssessmentID();

                    ModelState.Clear();
                    return(View());
                }
                ViewBag.ModuleList = await moduleRepository.AllAsync();

                return(View(assessment));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        [HttpGet] // Show result of a particular Student
        public async Task <IActionResult> ShowResult(string id)
        {
            try
            {
                var student = await studentRepository.FindByIdAsync(id);

                if (student == null)
                {
                    ViewBag.ErrorMsg = $"Could not find student: {id}";
                    return(RedirectToAction("Unknown", "Error"));
                }

                var assessmentResults = await assessmentResultRepository.GetStudentAssessmentResults(id);

                ShowStudentResultViewModel vm = new ShowStudentResultViewModel();
                vm.StudentName            = student.FirstName + " " + student.SurName;
                vm.Programme              = student.Programme.ProgrammeName;
                vm.StudentImage           = student.StudentImage;
                vm.listOfAssessmentResult = assessmentResults.ToList();

                return(View(vm));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Edit(string id,
                                               [Bind("TeacherID,FirstName,SurName,Password,AddressOne,AddressTwo,Town,County,MobilePhoneNumber,EmailAddress,EmergencyMobilePhoneNumber,TeacherPPS,ProgrammeFeePaid,GenderType,FullOrPartTime,TeacherImage,ProgrammeID")] Teacher teacher)
        {
            if (id != teacher.TeacherID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    teacherRepository.Update(teacher);
                    await teacherRepository.SaveChangesAsync();

                    return(RedirectToAction("Details", new { id = teacher.TeacherID }));
                }
                catch (DataAccessException e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                    if (!TeacherExists(teacher.TeacherID))
                    {
                        return(NotFound());
                    }
                    return(RedirectToAction("Unknown", "Error"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
            }
            return(View(teacher));
        }
        public async Task <IActionResult> Edit(string id, [Bind("ModuleID,ModuleName,ModuleDescription,ModuleCredits")] Module @module)
        {
            if (id != module.ModuleID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    moduleRepository.Update(module);
                    await moduleRepository.SaveChangesAsync();

                    return(RedirectToAction("Details", new { id = module.ModuleID }));
                }
                catch (DataAccessException e)
                {
                    if (!await ModuleExists(module.ModuleID))
                    {
                        return(NotFound());
                    }
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
            }
            return(View(module));
        }
Пример #10
0
        public async Task <IActionResult> Login(LoginVm login)
        {
            try
            {
                var user = await userManager.FindByNameAsync(login.UserName);

                if (user != null)
                {
                    var result = await signInManager.CheckPasswordSignInAsync(user, login.Password, false);

                    if (result.Succeeded)
                    {
                        var    appUser = userManager.Users.FirstOrDefault(x => x.NormalizedUserName == login.UserName.ToUpper());
                        string token   = await GenerateTokenAsync(appUser);

                        if (token != null)
                        {
                            HttpContext.Session.SetString("JWToken", token);
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }

                ViewBag.ErrorMsg = "Incorrect UserId or Password";
                return(View(login));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Edit(string id, [Bind("ProgrammeID,ProgrammeName,ProgrammeDescription,ProgrammeQQILevel,ProgrammeCredits,ProgrammeCost")] Programme programme)
        {
            if (id != programme.ProgrammeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    programmeRepository.Update(programme);
                    await programmeRepository.SaveChangesAsync();

                    return(RedirectToAction("Details", new { id = programme.ProgrammeID }));
                }
                catch (DataAccessException e)
                {
                    if (!ProgrammeExists(programme.ProgrammeID))
                    {
                        return(NotFound());
                    }
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
            }
            return(View(programme));
        }
        // GET: AssessmentResults/Create
        public async Task <IActionResult> Submit(string id)
        {
            try
            {
                var student = await studentRepository.FindByIdIncludeProgrammeAsync(id);

                if (student == null)
                {
                    ViewBag.StudentList = studentRepository.AllAsync();
                }
                else
                {
                    ViewBag.StudentId       = student.StudentID;
                    ViewBag.StudentFullName = student.FirstName + " " + student.SurName;
                }
                return(View());
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Edit(string id, [Bind("AssessmentResultID,AssessmentResultDescription,AssessmentResultMark,StudentID,ProgrammeID,AssessmentDate,ModuleID,AssessmentID")] AssessmentResult assessmentResult)
        {
            if (id != assessmentResult.AssessmentResultID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    assessmentResultRepository.Update(assessmentResult);
                    await assessmentResultRepository.SaveChangesAsync();
                }

                catch (DataAccessException e)
                {
                    if (!AssessmentResultExists(assessmentResult.AssessmentResultID))
                    {
                        return(NotFound());
                    }
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }
                catch (Exception e)
                {
                    ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                    return(RedirectToAction("Unknown", "Error"));
                }

                return(RedirectToAction(nameof(ShowAll)));
            }
            return(View(assessmentResult));
        }
 public async Task <IActionResult> Index()
 {
     try
     {
         return(View(await teacherRepository.AllIncludeProgrammeAsync()));
     }
     catch (DataAccessException e)
     {
         ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
         return(RedirectToAction("Unknown", "Error"));
     }
     catch (Exception e)
     {
         ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
         return(RedirectToAction("Unknown", "Error"));
     }
 }
        public async Task <IActionResult> Register(Student student, IFormFile image)
        {
            try
            {
                if (image != null)
                {
                    using (var stream = new MemoryStream())
                    {
                        image.CopyTo(stream);
                        student.StudentImage = stream.ToArray();
                    }
                }

                if (ModelState.IsValid)
                {
                    await studentRepository.AddAsync(student);

                    //Create Student Role for Authentication
                    string fullName = student.FirstName + " " + student.SurName;
                    await CreateStudentAsUserAsync(student.StudentID, student.Password, fullName);

                    // Commit changes
                    await studentRepository.SaveChangesAsync();

                    ModelState.Clear();

                    ViewBag.SuccessMsg = "Student Successfully Registered";

                    // Redirect to different view to show newly created student
                    return(RedirectToAction("Details", new { id = student.StudentID }));
                }
                return(View(student));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Submit(AssessmentResult assessmentResult)
        {
            try
            {
                string assessmentResultId = await GetAssessmentResultId();

                assessmentResult.AssessmentResultID = assessmentResultId;
                if (ModelState.IsValid)
                {
                    await assessmentResultRepository.AddAsync(assessmentResult);

                    await assessmentResultRepository.SaveChangesAsync();

                    return(RedirectToAction(nameof(ShowAll)));
                }

                //Student std = _context.Students
                //                .Include(m => m.Programme)
                //                .FirstOrDefault(m => m.StudentID == assessmentResult.StudentID);
                var student = await studentRepository.FindByIdIncludeProgrammeAsync(assessmentResult.StudentID);

                if (student == null)
                {
                    ViewBag.StudentList = await studentRepository.AllAsync();
                }
                else
                {
                    ViewBag.StudentId       = student.StudentID;
                    ViewBag.StudentFullName = student.FirstName + " " + student.SurName;
                }
                return(View(assessmentResult));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Register()
        {
            try
            {
                ViewBag.ProgrammeList = ViewBag.ProgrammeList = await programmeRepository.AllAsync();

                ViewBag.TeacherId = GetTeacherId();
                return(View());
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> ShowAll(string programmeID)
        {
            try
            {
                ViewBag.programmeList = await programmeRepository.AllAsync();

                var assessmentResults = assessmentResultRepository.AllResultsForProgrammeAsync(programmeID);
                return(View(assessmentResults));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> Register(Teacher teacher, IFormFile image)
        {
            try
            {
                if (image != null)
                {
                    using (var stream = new MemoryStream())
                    {
                        image.CopyTo(stream);
                        teacher.TeacherImage = stream.ToArray();
                    }
                }

                if (ModelState.IsValid)
                {
                    await teacherRepository.AddAsync(teacher);

                    await teacherRepository.SaveChangesAsync();

                    string fullName = teacher.FirstName + " " + teacher.SurName;
                    await CreateTeacherAsUserAsync(teacher.TeacherID, teacher.Password, fullName);

                    ViewBag.SuccessMsg = "Teacher Successfully Registered";

                    ModelState.Clear();

                    return(RedirectToAction("Details", new { id = teacher.TeacherID }));
                }
                return(View(teacher));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
Пример #20
0
        // GET: Assessments/Create
        public async Task <IActionResult> Create()
        {
            try
            {
                ViewBag.ModuleList = await moduleRepository.AllAsync();

                ViewBag.AssessmentID = await GetAssessmentID();

                return(View());
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            try
            {
                await teacherRepository.DeleteTeacherAsync(id);

                await teacherRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> DeleteConfirmed(string assessmentResultID)
        {
            try
            {
                await assessmentResultRepository.DeleteAssessmentResultAsync(assessmentResultID);

                await assessmentResultRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(ShowAll)));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }
        public async Task <IActionResult> DeleteConfirmed(string id)
        {
            try
            {
                await studentRepository.DeleteStudentAsync(id);

                await userManager.DeleteAsync(new AppUser { UserName = id });

                await studentRepository.SaveChangesAsync();

                return(RedirectToAction(nameof(ShowAll)));
            }
            catch (DataAccessException e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("Data Access exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
            catch (Exception e)
            {
                ViewBag.ErrorMsg = ErrorProcessing.ProcessException("General exception. ", e);
                return(RedirectToAction("Unknown", "Error"));
            }
        }