public ActionResult Edit(int id = 0) { Major model = new Major(); string action = "添加专业"; if (id > 0) { model = _majorService.GetByIdAsync(id); action = "修改专业"; } ViewBag.Action = action; List <SelectListItem> typeList = new List <SelectListItem>(); typeList.Add(new SelectListItem { Text = "本科", Value = "0" }); typeList.Add(new SelectListItem { Text = "研究生", Value = "1" }); ViewBag.typeList = typeList; 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; return(View(model)); }
public ActionResult Details(int id) { var major = _majorService.GetByIdAsync(id); if (major == null) { throw new Exception("专业不存在"); } ViewBag.WorkList = (_workService.GetListByMajorIdAsync(id, 3)) ?? new List <Instart.Models.Works>(); //ViewBag.CourseList = _courseService.GetListByMajor(3, id) ?? new List<Course>(); IEnumerable <Student> studentList = (_studentService.GetAllAsync()) ?? new List <Student>(); List <Student> majorStudents = new List <Student>(); foreach (Student student in studentList) { if (student.MajorId == id) { majorStudents.Add(student); } } ViewBag.MajorStudents = majorStudents; return(View(major)); }
public ActionResult Details(int id) { var major = _majorService.GetByIdAsync(id); if (major == null) { throw new Exception("专业不存在"); } ViewBag.WorkList = (_workService.GetListByMajorIdAsync(id, 3)) ?? new List <Instart.Models.Works>(); List <School> schoolList = _schoolService.GetListByMajorAsync(id, 6) ?? new List <Instart.Models.School>(); //计算录取比例 IEnumerable <Student> studentList = (_studentService.GetAllAsync()) ?? new List <Student>(); foreach (School school in schoolList) { int count = 0; foreach (Student student in studentList) { if (student.SchoolId == school.Id) { count++; } } school.AcceptRate = "0"; if (studentList.Count() > 0) { decimal rate = (decimal)count / studentList.Count(); school.AcceptRate = (rate * 100).ToString("f2"); } } ViewBag.SchoolList = schoolList; return(View(major)); }
public async Task <IActionResult> GetById([FromRoute] int id) { var result = await _majorService.GetByIdAsync(id); if (result == null) { return(NotFound()); } return(Ok(result)); }
public ActionResult Details(int id) { var major = _majorService.GetByIdAsync(id); if (major == null) { throw new Exception("专业不存在"); } ViewBag.WorkList = (_workService.GetListByMajorIdAsync(id, 3)) ?? new List <Instart.Models.Works>(); ViewBag.BannerList = (_bannerService.GetBannerListByPosAsync(Instart.Models.Enums.EnumBannerPos.Teacher)) ?? new List <Instart.Models.Banner>(); return(View(major)); }