public ActionResult Edit(int id = 0) { Student model = new Student(); string action = "添加学员"; if (id > 0) { model = _studentService.GetByIdAsync(id); action = "修改学员"; } ViewBag.Action = action; List <SelectListItem> teacherList = new List <SelectListItem>(); IEnumerable <Teacher> teachers = _teacherService.GetAllAsync(); foreach (var item in teachers) { teacherList.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } ViewBag.TeacherList = teacherList; List <SelectListItem> majorList = new List <SelectListItem>(); IEnumerable <Major> majors = _majorService.GetAllAsync(); foreach (var item in majors) { majorList.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } ViewBag.MajorList = majorList; List <SelectListItem> divisionList = new List <SelectListItem>(); IEnumerable <Division> divisions = _divisionService.GetAllAsync(); foreach (var item in divisions) { divisionList.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } ViewBag.DivisionList = divisionList; List <SelectListItem> campusList = new List <SelectListItem>(); IEnumerable <Campus> campuses = _campusService.GetAllAsync(); foreach (var item in campuses) { campusList.Add(new SelectListItem { Text = item.Name, Value = item.Id.ToString() }); } ViewBag.CampusList = campusList; return(View(model)); }
public async Task <IActionResult> GetAll() { try { var campusList = await _campusService.GetAllAsync(); return(Ok(campusList)); } catch (Exception e) { return(HttpExceptionMapper.ToHttpActionResult(e)); } }