public ScoredCourse GetScoreData(int studentId, int courseId) { var scoreServcies = new ScoreServices(_scrRep, _corRep, _usrRep); var courseServices = new CourseServices(_corRep, _usrRep, _comRep); var course = courseServices.GetCourseById(courseId); var scores = scoreServcies.GetScorebyStudentAndCourse(studentId, courseId); var scoresViewModel = new List <SimpleScore>(); foreach (var score in scores) { scoresViewModel.Add(new SimpleScore(score)); } scoresViewModel.Sort((m1, m2) => m1.ComponentName.CompareTo(m2.ComponentName)); var scoredCourse = new ScoredCourse() { Name = course.Name, ScoreList = scoresViewModel }; return(scoredCourse); }
public ActionResult StudentsEnrolled(IEnumerable <StudentEnrollementViewModel> list) { var scoreServices = new ScoreServices(_scoreRepository, _courseRepository, _userRepository); var componentServices = new ComponentServices(_componentRepository, _courseRepository); var userServices = new UserServices(_userRepository); foreach (var s in list) { foreach (var scor in s.scores) { Score ss = new Score() { Id = scor.Id, Value = scor.Value, Component = componentServices.GetById(scor.Component.Id), Student = (Student)userServices.GetUserById(scor.Student.Id) }; if (ss.Value > ss.Component.MaximumPoints) { return(RedirectToAction("StudentsEnrolled", "Lecturer", new { id = ss.Component.Course.Id, error = true })); } else { scoreServices.SaveScore(ss); } } } return(RedirectToAction("Index", "Lecturer")); }
public ActionResult StudentsEnrolled(int id, bool?error) { if (Session["userId"] == null) { return(RedirectToAction("Index", "Home")); } ViewBag.Email = Session["email"]; if (error == true) { ModelState.AddModelError("prag_error", "Nemoguće unjeti više bodova od maksimalnog broj bodova po komponenti!"); } var courseServices = new CourseServices(_courseRepository, _userRepository, _componentRepository); var course = courseServices.GetCourseById(id); ViewBag.Title = course.Name; var studentServices = new StudentServices(_userRepository); var scoreServices = new ScoreServices(_scoreRepository, _courseRepository, _userRepository); IList <Student> enrolledStudents = studentServices.GetStudentsByCourse(course); IList <StudentEnrollementViewModel> enroll = new List <StudentEnrollementViewModel>(); foreach (Student s in enrolledStudents) { IList <Score> score = scoreServices.GetScorebyStudentAndCourse(s.Id, course.Id); enroll.Add(new StudentEnrollementViewModel(score)); } return(View(enroll)); }
/// <summary> /// /// </summary> /// <param name="id">Course id</param> /// <returns></returns> public ActionResult ScoreInfo(int id) { if (Session["userId"] == null) { return(RedirectToAction("Index", "Home")); } ViewBag.Email = Session["email"]; ViewBag.Title = "Bodovi"; var studentId = (int)Session["userId"]; var scoreServcies = new ScoreServices(_scoreRepository, _courseRepository, _userRepository); var courseServices = new CourseServices(_courseRepository, _userRepository, _componentRepository); var course = courseServices.GetCourseById(id); var scores = scoreServcies.GetScorebyStudentAndCourse(studentId, id); var scoresViewModel = new List <ScoreViewModel>(); foreach (var score in scores) { scoresViewModel.Add(new ScoreViewModel(score)); } scoresViewModel.Sort((m1, m2) => m1.ComponentName.CompareTo(m2.ComponentName)); var scoredCourse = new ScoredCourseViewModel() { Name = course.Name, scoreList = scoresViewModel }; return(View(scoredCourse)); }
public void GetScorebyStudentAndCourseTest_DefaultScore() { Mock <IUserRepository> usrRepMock = new Mock <IUserRepository>(); Mock <ICourseRepository> corRepMock = new Mock <ICourseRepository>(); Mock <IScoreRepository> scrRepMock = new Mock <IScoreRepository>(); var componentList = new List <Component>(); componentList.Add(new Component()); Mock <Course> courseMock = new Mock <Course>(); courseMock.Setup(c => c.Components).Returns(componentList); corRepMock.Setup(c => c.GetById(It.IsAny <int>())).Returns(courseMock.Object); usrRepMock.Setup(c => c.GetById(It.IsAny <int>())).Returns(student); scrRepMock.Setup(c => c.GetByStudentIdAndComponentId(It.IsAny <Student>(), It.IsAny <Component>())).Returns <Score>(null); scrRepMock.Setup(c => c.CreateOrUpdate(It.IsAny <Score>())).Returns(new Score() { Value = 0 }); var scoreService = new ScoreServices(scrRepMock.Object, corRepMock.Object, usrRepMock.Object); var scores = scoreService.GetScorebyStudentAndCourse(1, 1); Assert.IsNotNull(scores); Assert.IsFalse(scores.Count == 0); Assert.AreEqual(0, scores[0].Value); }
public CourseFormTests() { var nhs = new NHibernateService2(); _userRepository = new UserRepository(nhs); _courseRepository = new CourseRepository(nhs); _componentRepository = new ComponentRepository(nhs); _scoreRepository = new ScoreRepository(nhs); _userServices = new UserServices(_userRepository); _courseServices = new CourseServices(_courseRepository, _userRepository, _componentRepository); _scoreServices = new ScoreServices(_scoreRepository, _courseRepository, _userRepository); }
public void Setup() { this.score = new Score { Id = 1, Points = 5, UserIdFrom = 1, UserFrom = new User { Email = "*****@*****.**", Password = "******", Username = "******" }, User = new User { Email = "*****@*****.**", Password = "******", Username = "******" }, UserIdTo = 2 }; this.scoreRepository = A.Fake <IRepositoryScore>(); this.userService = A.Fake <IUserServices>(); this.scoreService = new ScoreServices(this.scoreRepository, this.userService); }
public ActionResult ComponentStatistics(int id) { if (Session["userId"] == null) { return(RedirectToAction("Index", "Home")); } ViewBag.Email = Session["email"]; ViewBag.Title = "Statistics"; var courseService = new CourseServices(_courseRepository, _userRepository, _componentRepository); var componentService = new ComponentServices(_componentRepository, _courseRepository); var scoreService = new ScoreServices(_scoreRepository, _courseRepository, _userRepository); var course = courseService.GetCourseById(id); IList <Component> comp = new List <Component>(); foreach (var c in course.Components) { comp.Add(c); } IList <ComponentStatisticsViewModel> results = new List <ComponentStatisticsViewModel>(); foreach (var c in comp) { var scores = scoreService.GetByComponent(c.Id); float sum = 0; float maxSum = 0; foreach (var s in scores) { sum += s.Value; maxSum += c.MaximumPoints; } results.Add(new ComponentStatisticsViewModel(c.Name, (float)sum / maxSum, c.MaximumPoints, c.Course.Id)); } return(View(results)); }