public async Task <IActionResult> Edit(int id, [Bind("FirstName,LastName,cgpa,Id,Year,Semester,DepartmentId,Email")] Student student) { if (id != student.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(student); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!StudentExists(student.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, nameof(Department.Id), nameof(Department.Name), student.DepartmentId); return(View(student)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,DepartmentId,Code,Name,Credits")] Course course) { if (id != course.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(course); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CourseExists(course.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["DepartmentId"] = new SelectList(_context.Departments, nameof(Department.Id), nameof(Department.Name), course.DepartmentId); return(View(course)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Year,Semester,Number,CourseId,TeacherId")] Sections sections) { if (id != sections.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(sections); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SectionsExists(sections.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["CourseId"] = new SelectList(_context.Courses, nameof(Course.Id), nameof(Course.Code), sections.CourseId); ViewData["TeacherId"] = new SelectList(_context.Teachers, nameof(Teacher.Id), nameof(Teacher.FirstName), sections.TeacherId); return(View(sections)); }
public async Task <IActionResult> Edit(int id, [Bind("SectionId,StudentId,IsFinished,gpa")] Enrollment enrollment) { if (id != enrollment.SectionId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(enrollment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!EnrollmentExists(enrollment.SectionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["SectionId"] = new SelectList(_context.Sections, nameof(Sections.Id), nameof(Sections.Number), enrollment.SectionId); ViewData["StudentId"] = new SelectList(_context.Students, nameof(Student.Id), nameof(Student.FirstName), enrollment.StudentId); return(View(enrollment)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] Department department) { if (id != department.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(department); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(department.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(department)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,ExamName,Score,OutOf,EnrollmentStudentId,EnrollmentSectionId")] Mark mark) { if (id != mark.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(mark); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MarkExists(mark.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["EnrollmentSectionId"] = new SelectList(_context.Enrollments, "SectionId", "SectionId", mark.EnrollmentSectionId); return(View(mark)); }
public async Task <IActionResult> Profile(int id) { try { var user = _userManager.GetUserName(User); var student = await _context.Students.Include(s => s.Enrollments) .ThenInclude(e => e.Section) .ThenInclude(se => se.Course) .Where(st => st.Email == user) .FirstOrDefaultAsync(); var enrolls = _context.Enrollments.Include(e => e.marks) .Where(s => s.StudentId == student.Id); var department = await _context.Departments.Where(d => d.Id == student.DepartmentId).FirstOrDefaultAsync(); foreach (var enroll in enrolls) { decimal sum = 0; foreach (var mark in enroll.marks) { sum += mark.OutOf; } if (sum >= 100) { enroll.IsFinished = true; enroll.gpa = enroll.CalculateGpa(); _context.Update(enroll); } } await _context.SaveChangesAsync(); decimal creditSum = 0; decimal gpamul = 0; foreach (var enroll in enrolls) { creditSum += Convert.ToDecimal(enroll.Section.Course.Credits); gpamul += Convert.ToDecimal(enroll.Section.Course.Credits * enroll.gpa); } student.cgpa = gpamul / creditSum; if (student == null) { return(NotFound()); } student.Department = department; return(View(student)); } catch (Exception e) { return(View()); } }