private async Task setDbErrorMessage(Department dbValues, Department clientValues, Kodutoo10VeebruarContext context) { 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."); }
public void PopulateDepartmentsDropDownList(Kodutoo10VeebruarContext _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(Kodutoo10VeebruarContext 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(Kodutoo10VeebruarContext 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); } } } }
public AboutModel(Kodutoo10VeebruarContext context) { _context = context; }