Ejemplo n.º 1
0
        public void PopulateDepartmentsDropDownList(TalTechUniversityContext _context,
                                                    object selectedDepartment = null)
        {
            var departmentsQuery = from d in _context.Departments
                                   orderby d.Name // Sort by name.
                                   select d;

            DepartmentNameSL = new SelectList(departmentsQuery.AsNoTracking(),
                                              "DepartmentID", "Name", selectedDepartment);
        }
        public void PopulateAssignedCourseData(TalTechUniversityContext context, Instructor instructor)
        {
            var allCourses        = context.Courses;
            var instructorCourses = new HashSet <int>(
                instructor.CourseAssignments.Select(c => c.CourseID));

            AssignedCourseDataList = new List <AssignedCourseData>();
            foreach (var course in allCourses)
            {
                AssignedCourseDataList.Add(new AssignedCourseData
                {
                    CourseID = course.CourseID,
                    Title    = course.Title,
                    Assigned = instructorCourses.Contains(course.CourseID)
                });
            }
        }
        public void UpdateInstructorCourses(TalTechUniversityContext context, string[] selectedCourses, Instructor instructorToUpdate)
        {
            if (selectedCourses == null)
            {
                instructorToUpdate.CourseAssignments = new List <CourseAssignment>();
                return;
            }

            var selectedCoursesHS = new HashSet <string>(selectedCourses);
            var instructorCourses = new HashSet <int>
                                        (instructorToUpdate.CourseAssignments.Select(c => c.Course.CourseID));

            foreach (var course in context.Courses)
            {
                if (selectedCoursesHS.Contains(course.CourseID.ToString()))
                {
                    if (!instructorCourses.Contains(course.CourseID))
                    {
                        instructorToUpdate.CourseAssignments.Add(
                            new CourseAssignment
                        {
                            InstructorID = instructorToUpdate.ID,
                            CourseID     = course.CourseID
                        });
                    }
                }
                else
                {
                    if (instructorCourses.Contains(course.CourseID))
                    {
                        CourseAssignment courseToRemove
                            = instructorToUpdate
                              .CourseAssignments
                              .SingleOrDefault(i => i.CourseID == course.CourseID);
                        context.Remove(courseToRemove);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private async Task setDbErrorMessage(Department dbValues, Department clientValues, TalTechUniversityContext context)
        {
            //error message for each column
            if (dbValues.Name != clientValues.Name)
            {
                ModelState.AddModelError("Department.Name",
                                         $"Current value: {dbValues.Name}");
            }
            if (dbValues.Budget != clientValues.Budget)
            {
                ModelState.AddModelError("Department.Budget",
                                         $"Current value: {dbValues.Budget:c}");
            }
            if (dbValues.StartDate != clientValues.StartDate)
            {
                ModelState.AddModelError("Department.StartDate",
                                         $"Current value: {dbValues.StartDate:d}");
            }
            if (dbValues.InstructorID != clientValues.InstructorID)
            {
                Instructor dbInstructor = await _context.Instructors
                                          .FindAsync(dbValues.InstructorID);

                ModelState.AddModelError("Department.InstructorID",
                                         $"Current value: {dbInstructor?.FullName}");
            }

            ModelState.AddModelError(string.Empty,
                                     "The record you attempted to edit "
                                     + "was modified by another user after you. The "
                                     + "edit operation was canceled and the current values in the database "
                                     + "have been displayed. If you still want to edit this record, click "
                                     + "the Save button again.");
        }
Ejemplo n.º 5
0
 public AboutModel(TalTechUniversityContext context)
 {
     _context = context;
 }
Ejemplo n.º 6
0
 public IndexModel(TalTechUniversityContext context)
 {
     _context = context;
 }