public IActionResult Create() { var instructor = _instructorRepository.GetInstructors(); ViewData["iId"] = new SelectList(instructor, "Id", "Name"); var batch = _batchRepository.GetBatches(); ViewData["bId"] = new SelectList(batch, "Id", "Name"); return(View()); }
public ActionResult Index(int?id, int?courseId) { var viewModel = new InstructorList(); viewModel.Instructors = instructorRepository.GetInstructors(); if (id != null) { ViewBag.InstructorId = id.Value; viewModel.Courses = viewModel.Instructors.Single(i => i.Id == id.Value).Courses; } if (courseId != null) { ViewBag.CourseId = courseId.Value; viewModel.Enrollments = viewModel.Courses.Single(x => x.Id == courseId).Enrollments; } return(View(viewModel)); }
private void ListInstructors(int?currentInstructorId = null) { ViewBag.InstructorId = new SelectList(instructorRepository.GetInstructors(), "Id", "FullName", currentInstructorId); }
// // GET: /Instructor/ public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page, int?id, int?courseID) { ViewBag.menu = MENU; ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "Name_desc" : ""; ViewBag.FirstNameSortParm = sortOrder == "FirstName" ? "FirstName_desc" : "FirstName"; ViewBag.DateSortParm = sortOrder == "Date" ? "Date_desc" : "Date"; ViewBag.LocationSortParm = sortOrder == "Loc" ? "Loc_desc" : "Loc"; InstructorIndexData viewModel = new InstructorIndexData(); if (searchString != null) { page = 1; } else { searchString = currentFilter; } string keyword = string.IsNullOrEmpty(searchString) ? null : searchString.ToUpper(); ViewBag.CurrentFilter = searchString; var instructors = repository.GetInstructors() .Include(i => i.OfficeAssignment) .Include(i => i.Courses.Select(x => x.Department)); if (!string.IsNullOrEmpty(keyword)) { instructors = instructors.Where(x => x.LastName.ToUpper().Contains(keyword) || x.FirstMidName.ToUpper().Contains(keyword)); } if (id != null) { ViewBag.PersonID = id.Value; viewModel.Courses = instructors.Where(i => i.PersonID == id.Value).Single().Courses; } if (courseID != null) { ViewBag.CourseID = courseID.Value; viewModel.Enrollments = viewModel.Courses.Where(x => x.CourseID == courseID).Single().Enrollments; } switch (sortOrder) { case "Name_desc": instructors = instructors.OrderByDescending(x => x.LastName); break; case "FirstName": instructors = instructors.OrderBy(x => x.FirstMidName); break; case "FirstName_desc": instructors = instructors.OrderByDescending(x => x.FirstMidName); break; case "Date": instructors = instructors.OrderBy(x => x.HireDate); break; case "Date_desc": instructors = instructors.OrderByDescending(x => x.HireDate); break; case "Loc": instructors = instructors.OrderBy(x => x.OfficeAssignment.Location); break; case "Loc_desc": instructors = instructors.OrderByDescending(x => x.OfficeAssignment.Location); break; default: instructors = instructors.OrderBy(x => x.LastName); break; } int pageSize = Constants.PAGE_SIZE; int pageNumber = (page ?? 1); viewModel.Instructors = instructors.ToPagedList(pageNumber, pageSize); return(View(viewModel)); }
public async Task <IActionResult> OnPostAsync(Guid id) { if (!ModelState.IsValid) { return(Page()); } var departmentToUpdate = await _departmentRepository.GetDepartmentAsync(id); // null means Department was deleted by another user. if (departmentToUpdate == null) { return(HandleDeletedDepartment()); } // Update the RowVersion to the value when this entity was // fetched. If the entity has been updated after it was // fetched, RowVersion won't match the DB RowVersion and // a DbUpdateConcurrencyException is thrown. // A second postback will make them match, unless a new // concurrency issue happens. _departmentRepository .GetDbEntityEntry(departmentToUpdate) .Property("RowVersion").OriginalValue = Department.RowVersion; if (await TryUpdateModelAsync <Department>( departmentToUpdate, "Department", s => s.DepartmentName, s => s.FoundedDate, s => s.Budget, s => s.DepartmentChairId)) { try { await _departmentRepository.UpdateAsync(departmentToUpdate); return(RedirectToPage("./Index")); } catch (DbUpdateConcurrencyException ex) { var exceptionEntry = ex.Entries.Single(); var clientValues = (Department)exceptionEntry.Entity; var databaseEntry = exceptionEntry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError(string.Empty, "Unable to save. " + "The department was deleted by another user."); return(Page()); } var dbValues = (Department)databaseEntry.ToObject(); await SetDbErrorMessage(dbValues, clientValues); // Save the current RowVersion so next postback matches unless an new concurrency issue happens. Department.RowVersion = (byte[])dbValues.RowVersion; // Must clear the model error for the next postback. ModelState.Remove("Department.RowVersion"); } } DepartmentChairSelectList = new SelectList(_instructorRepository.GetInstructors(), "Id", "FullName", departmentToUpdate.DepartmentChairId); return(Page()); }
public ActionResult Index(string sortOrder, string searchString, int?page) { string keyword = string.IsNullOrEmpty(searchString) ? null : searchString.ToUpper(); InstructorIndexData viewModel = new InstructorIndexData(); if (searchString != null) { page = 1; } var instructors = repository.GetInstructors() .Include(i => i.OfficeAssignment) .Include(i => i.Courses.Select(x => x.Department)); if (!string.IsNullOrEmpty(keyword)) { instructors = instructors.Where(x => x.LastName.ToUpper().Contains(keyword) || x.FirstMidName.ToUpper().Contains(keyword)); } switch (sortOrder) { case "Name_desc": instructors = instructors.OrderByDescending(x => x.LastName); break; case "FirstName": instructors = instructors.OrderBy(x => x.FirstMidName); break; case "FirstName_desc": instructors = instructors.OrderByDescending(x => x.FirstMidName); break; case "Date": instructors = instructors.OrderBy(x => x.HireDate); break; case "Date_desc": instructors = instructors.OrderByDescending(x => x.HireDate); break; case "Loc": instructors = instructors.OrderBy(x => x.OfficeAssignment.Location); break; case "Loc_desc": instructors = instructors.OrderByDescending(x => x.OfficeAssignment.Location); break; default: instructors = instructors.OrderBy(x => x.LastName); break; } int pageSize = Constants.PAGE_SIZE; int pageNumber = (page ?? 1); var l = instructors.ToPagedList(pageNumber, pageSize); var lx = l.Select(x => new { PersonID = x.PersonID, LastName = x.LastName, FirstMidName = x.FirstMidName, HireDate = x.HireDate, OfficeAssignment = new { Location = x.OfficeAssignment == null ? null : x.OfficeAssignment.Location }, Courses = x.Courses == null ? null : x.Courses.Select(c => new { CourseID = c.CourseID, Title = c.Title }) }); Pager pager = new Pager(l.TotalItemCount, l.PageNumber, l.PageSize); Dictionary <string, object> res = new Dictionary <string, object> { { "pager", pager }, { "model", lx } }; return(Json(res, JsonRequestBehavior.AllowGet)); }
public List <Instructor> GetInstructors() { return(_instructorRepository.GetInstructors()); }
public IActionResult Index() { return(View(_instructorRepository.GetInstructors())); }