Как рассчитать баллы для студента в ASP.NET mvc5
я хочу рассчитать средние оценки для студента
Что я уже пробовал:
это моя модель представления
public class StudentCoursesViewModel { public uniscoreEntities db = new uniscoreEntities(); public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public int Code { get; set; } public string CourseName { get; set; } public int Credit { get; set; } public int Mark { get; set; } public string Grade { get; set; } }
это мой контроллер
namespace UniScore.Controllers { public class StudentCoursesController : Controller { // GET: StudentCourses [AcceptVerbs(HttpVerbs.Get)] public ActionResult Index(int? id) { uniscoreEntities db = new uniscoreEntities(); Student student = db.Students.Find(id); List<StudentCoursesViewModel> StudentCoursesList = new List<StudentCoursesViewModel>(); // var coursesList = db.Courses.ToList(); // var StudentCourses = db.Student_Course.ToList(); Student_Course injec = new Student_Course(); var StudentCourses = db.Student_Course.Where(b => b.Student_id == id); foreach (var item in StudentCourses) { StudentCoursesViewModel objele = new StudentCoursesViewModel(); Student studento = db.Students.Find(item.Student_id); objele.FirstName = studento.FirstName; objele.LastName = studento.LastName; Course course = db.Courses.Find(item.Course_id); objele.CourseName = course.CourseName; objele.Code = course.Code; objele.Credit = course.Credit; // Student_Course testy = db.Student_Courses.Find(item.Marks); objele.Grade = item.Grade; objele.Mark = item.Mark; StudentCoursesList.Add(objele); } return View(StudentCoursesList); } } }
это моя точка зрения
@model IEnumerable<UniScore.ViewModels.StudentCoursesViewModel> @{ ViewBag.Title = "Details"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Details</h2> <div> <h4>Student</h4> <hr /> <dl class="dl-horizontal"> <dt> @Html.DisplayNameFor(model => model.FirstName) </dt> <dd> </dd> <dt> @Html.DisplayNameFor(model => model.LastName) </dt> <dd> </dd> </dl> </div> <table class="table"> <tr> <th> @Html.DisplayNameFor(model => model.CourseName) </th> <th> @Html.DisplayNameFor(model => model.Code) </th> <th> @Html.DisplayNameFor(model => model.Credit) </th> <th> @Html.DisplayNameFor(model => model.Mark) </th> <th> @Html.DisplayNameFor(model => model.Grade) </th> </tr> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.CourseName) </td> <td> @Html.DisplayFor(modelItem => item.Code) </td> <td> @Html.DisplayFor(modelItem => item.Credit) </td> <td> @Html.DisplayFor(modelItem => item.Mark) </td> <td> @Html.DisplayFor(modelItem => item.Grade) </td> </tr> } </table> <p> AVERAGE MARKS: </p> <p> @Html.ActionLink("Back to List", "Index", "Students") </p>