public async Task <SubjectStudent> AddAsync(SubjectStudent newSubjectStudent) { _context.SubjectStudent.Add(newSubjectStudent); await _context.SaveChangesAsync(); return(newSubjectStudent); }
public async Task <bool> UpdateAsync(SubjectStudent subjectStudent) { if (!await SubjectStudentExists(subjectStudent.Id)) { return(false); } _context.SubjectStudent.Update(subjectStudent); await _context.SaveChangesAsync(); return(true); }
public static SubjectStudentDto ToSubjectStudentDto(this SubjectStudent subjectStudent) { return(new SubjectStudentDto { Id = subjectStudent.Id, StudentName = subjectStudent.Student.User.Name, StudentBirthDay = subjectStudent.Student.User.BirthDay.GetValueOrDefault().ToShortDateString(), StudentGrade = subjectStudent.Grade.GetValueOrDefault(), StudentRegistrationNumber = subjectStudent.Student.RegistrationNumber.GetValueOrDefault() }); }
public async Task <bool> AddSubjectStudentAsync(Student newStudent, int subjectId) { _context.Students.Add(newStudent); await _context.SaveChangesAsync(); var newSubjectStudent = new SubjectStudent { StudentId = newStudent.Id, SubjectId = subjectId }; _context.SubjectStudent.Add(newSubjectStudent); await _context.SaveChangesAsync(); return(true); }
public void Add_Mark_Correctly_To_Unexisting_SubjectStudent() { var mockedSubjectStudentRepo = new Mock <IRepository <SubjectStudent> >(); var mockedMarksRepo = new Mock <IRepository <Mark> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new MarksManagementService( mockedSubjectStudentRepo.Object, mockedMarksRepo.Object, () => mockedUnitOfWork.Object); var subjStudent1 = new SubjectStudent { Count = 0, SubjectId = 1, MarkId = 1, StudentId = "id1" }; var subjStudent2 = new SubjectStudent { Count = 0, SubjectId = 2, MarkId = 2, StudentId = "id2" }; var subjStudent3 = new SubjectStudent { Count = 0, SubjectId = 3, MarkId = 3, StudentId = "id3" }; var subjectStudent = new List <SubjectStudent>() { subjStudent1, subjStudent2, subjStudent3 }; var expected = 4; mockedUnitOfWork.Setup(x => x.Commit()); mockedSubjectStudentRepo .Setup(x => x.GetFirst(It.IsAny <Expression <Func <SubjectStudent, bool> > >())) .Returns((Expression <Func <SubjectStudent, bool> > predicate) => subjectStudent.FirstOrDefault(predicate.Compile())); mockedSubjectStudentRepo .Setup(x => x.Add(It.IsAny <SubjectStudent>())) .Callback((SubjectStudent predicate) => subjectStudent.Add(predicate)); service.AddMark("id4", 1, 1); Assert.AreEqual(expected, subjectStudent.Count()); }
public void Call_UnitOfWork_Commit_Method_Once_When_ThereIsUnexistingSubjectstudent() { var mockedSubjectStudentRepo = new Mock <IRepository <SubjectStudent> >(); var mockedMarksRepo = new Mock <IRepository <Mark> >(); var mockedUnitOfWork = new Mock <IUnitOfWork>(); var service = new MarksManagementService( mockedSubjectStudentRepo.Object, mockedMarksRepo.Object, () => mockedUnitOfWork.Object); var subjStudent1 = new SubjectStudent { Count = 0, SubjectId = 1, MarkId = 1, StudentId = "id1" }; var subjStudent2 = new SubjectStudent { Count = 0, SubjectId = 2, MarkId = 2, StudentId = "id2" }; var subjStudent3 = new SubjectStudent { Count = 0, SubjectId = 3, MarkId = 3, StudentId = "id3" }; var subjectStudent = new List <SubjectStudent>() { subjStudent1, subjStudent2, subjStudent3 }; mockedUnitOfWork.Setup(x => x.Commit()); mockedSubjectStudentRepo .Setup(x => x.GetFirst(It.IsAny <Expression <Func <SubjectStudent, bool> > >())) .Returns((Expression <Func <SubjectStudent, bool> > predicate) => subjectStudent.FirstOrDefault(predicate.Compile())); mockedSubjectStudentRepo .Setup(x => x.Add(It.IsAny <SubjectStudent>())) .Callback((SubjectStudent predicate) => subjectStudent.Add(predicate)); service.AddMark("id4", 1, 1); mockedUnitOfWork.Verify(x => x.Commit(), Times.Once); }
public void СonfirmationStudent(int studentId) { using var repositoriesContainer = new LmPlatformRepositoriesContainer(); var student = GetStudent(studentId); student.Confirmed = true; UpdateStudent(student); var subjects = repositoriesContainer.SubjectRepository.GetSubjects(student.GroupId) .Where(e => !e.IsArchive); foreach (var subject in subjects) { if (!subject.SubjectGroups.Any(e => e.SubjectStudents.Any(x => x.StudentId == student.Id))) { var firstOrDefault = subject.SubjectGroups.FirstOrDefault(e => e.GroupId == student.GroupId); if (firstOrDefault != null) { var subjectGroupId = firstOrDefault.Id; var modelFirstSubGroup = repositoriesContainer.SubGroupRepository.GetBy( new Query <SubGroup>(e => e.SubjectGroupId == subjectGroupId && e.Name == "first")); var subjectStudent = new SubjectStudent { StudentId = studentId, SubGroupId = modelFirstSubGroup.Id, SubjectGroupId = subjectGroupId }; repositoriesContainer.RepositoryFor <SubjectStudent>().Save(subjectStudent); repositoriesContainer.ApplyChanges(); } } } }