public void AddGrade() { //create the student var newStudent = new Student() { FirstName = "Mikesh", LastName = "Mistry" }; //add the student studentRepository.Add(newStudent); //Find the student var foundStudent = studentRepository.GetAll().ToList(); //create a course var newCourse = new Course() { Name = "Introduction To C# Programming", Description = "Introduction To C# Programming" }; //add the course to the database courseRepository.Add(newCourse); //find the course var foundCourse = courseRepository.GetAll().ToList(); //create a new grade var newGrade = new Grade() { Student = newStudent, Course = newCourse, LetterGrade = "A+" }; //add the grade gradeRepository.Add(newGrade); //find the grade var foundGrade = gradeRepository.Find(grade => grade.Student.StudentId == foundStudent[0].StudentId && grade.Course.CourseId == foundCourse[0].CourseId ).FirstOrDefault(); //test to see if we found the grade Assert.IsNotNull(foundGrade); //check are all the values the same Assert.AreEqual(foundGrade.Course.CourseId, foundCourse[0].CourseId); Assert.AreEqual(foundGrade.Student.StudentId, foundStudent[0].StudentId); Assert.AreEqual(foundGrade.LetterGrade, newGrade.LetterGrade); }
public ActionResult Create(Grade insertingGrade) { var grade = new Grade(); var studentList = from student in studentRepository.List select student; var bookList = from book in bookRespository.List select book; var chapterList = from chapter in chapterRepository.List select chapter; var studentExist = studentRepository.List.Where(s => s.StudentId == insertingGrade.Student_ID).Count(); var assignedChapter = gradeRepository.List.Where(g => g.Student_ID == insertingGrade.Student_ID && g.Book_ID == insertingGrade.Book_ID && g.Chapter_ID == insertingGrade.Chapter_ID).Count(); if (studentExist == 0) { ViewBag.studentExist = "The Student ID: " + insertingGrade.Student_ID + " was not found"; ViewBag.Student_ID = new SelectList(studentList, "StudentId", "Name"); ViewBag.Book_ID = new SelectList(bookList, "BookId", "Book_Name"); ViewBag.Chapter_ID = new SelectList(chapterList, "ChapterID", "ChapterDescription"); return(PartialView("_Create", insertingGrade)); } if (assignedChapter > 0) { ViewBag.assignedChapter = "This Student has the Chapter: " + insertingGrade.Chapter_ID + " of the Book " + insertingGrade.Book_ID + " assigned already"; ViewBag.Student_ID = new SelectList(studentList, "StudentId", "Name"); ViewBag.Book_ID = new SelectList(bookList, "BookId", "Book_Name"); ViewBag.Chapter_ID = new SelectList(chapterList, "ChapterID", "ChapterDescription"); return(PartialView("_Create", insertingGrade)); } if (ModelState.IsValid) { if (insertingGrade != null) { grade.Student_ID = insertingGrade.Student_ID; grade.Book_ID = insertingGrade.Book_ID; grade.Chapter_ID = insertingGrade.Chapter_ID; grade.Homework = insertingGrade.Homework; grade.Excercise = insertingGrade.Excercise; grade.Participation = insertingGrade.Participation; grade.CreateDate = DateTime.Now; } gradeRepository.Add(grade); return(Json(new { success = true })); } //var studentList = from student in studentRepository.List select student; //var bookList = from book in bookRespository.List select book; //var chapterList = from chapter in chapterRepository.List select chapter; ViewBag.Student_ID = new SelectList(studentList, "StudentId", "Name"); ViewBag.Book_ID = new SelectList(bookList, "BookId", "Book_Name"); ViewBag.Chapter_ID = new SelectList(chapterList, "ChapterID", "ChapterDescription"); return(PartialView("_Create", insertingGrade)); }
// ReSharper disable once UnusedMember.Global public void Post(GradeUpsertRequest request) { Guard.IsTrue(lessonId => 0 < lessonId, request.LessonId); Guard.AgainstEmpty(request.Provider); Guard.AgainstEmpty(request.ProviderId); var existingUser = UserHelpers.GetExistingUser(request, UserRepository); Guard.IsTrue(eu => eu.IsNew == false, existingUser); Guard.AgainstEmpty(request.StudentProvider); Guard.AgainstEmpty(request.StudentProviderId); var existingStudent = UserHelpers.GetExistingUser(new LessonDeleteRequest { Provider = request.StudentProvider, ProviderId = request.StudentProviderId }, UserRepository); Guard.IsTrue(eu => eu.IsNew == false, existingStudent); Guard.IsTrue(es => es.IsStudent, existingStudent); var lesson = LessonRepository.Find(request.LessonId); if (lesson == null || lesson.IsDeleted) { throw new HttpError(HttpStatusCode.NotFound, "NotFound"); } if (request.Provider != lesson.Provider || request.ProviderId != lesson.ProviderId) { throw new HttpError(HttpStatusCode.Unauthorized, "Unauthorized"); } var grade = GradeRepository.GetGrade(request.LessonId, request.StudentProvider, request.ProviderId); if (grade == null) { grade = new GradeModel { LessonId = request.LessonId, StudentProvider = request.StudentProvider, StudentProviderId = request.StudentProviderId, TeacherProvider = request.Provider, TeacherProviderId = request.ProviderId, Grade = request.Grade, Comments = request.Comments }; GradeRepository.Add(grade); } else { grade.LessonId = request.LessonId; grade.StudentProvider = request.StudentProvider; grade.StudentProviderId = request.StudentProviderId; grade.TeacherProvider = request.Provider; grade.TeacherProviderId = request.ProviderId; grade.Grade = request.Grade; grade.Comments = request.Comments; grade.UpdateDateUtc = DateTime.UtcNow; GradeRepository.Update(grade); } }