Example #1
0
        public void StudentWhenDocumentExists()
        {
            var exp   = StudentQuery.GetStudentInfo("1111111111");
            var studn = _students.AsQueryable().Where(exp).FirstOrDefault();

            Assert.AreNotEqual(null, studn);
        }
Example #2
0
        public Message RegisterStudentToCourse(StudentIdCourseId studentIdCourseId)
        {
            Message msg = new Message();

            CourseQuery courseQuery = new CourseQuery();
            StudentCourseCollegeQuery studentCourseCollegeQuery = new StudentCourseCollegeQuery();
            StudentQuery studentQuery = new StudentQuery();


            if (query.IsStudentRegisteredtoCourse(context, studentIdCourseId.StudentId, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "Student is already registered to the course";
            }
            else if (!query.StudentExists(context, studentIdCourseId.StudentId) ||
                     !courseQuery.courseExistsOnId(context, studentIdCourseId.CourseId))
            {
                msg.status  = false;
                msg.message = "The Student/Course is not registered";
            }


            var college = AllotCollege(studentIdCourseId);

            if (college == null)
            {
                msg.status  = false;
                msg.message = "No colleges currently offer this course";
            }

            StudentCourseCollege studentCourseCollege = new StudentCourseCollege()
            {
                CollegeId = college.Id,
                StudentId = studentIdCourseId.StudentId,
                CourseId  = studentIdCourseId.CourseId,
            };

            try
            {
                studentCourseCollegeQuery.RegisterStudentToCourseAndCollege(context, studentCourseCollege);
                var course = courseQuery.GetCourseById(context, studentIdCourseId.CourseId);
                msg.status  = true;
                msg.message = $"Alloted College: {college.Name} (Id : {college.Id})\n for Course : {course.courseName} (id : {course.Id})";
            }
            catch (Exception e)
            {
                msg.status  = false;
                msg.message = $"Internal Error : {e.Message}";
            }

            return(msg);
        }
Example #3
0
        public async Task <QueryResult <Student> > GetStudentsAsync(StudentQuery queryObj)
        {
            var result = new QueryResult <Student>();

            var query = _context.Students
                        .Include(s => s.ClassSection)
                        .ThenInclude(cs => cs.Class)
                        .AsQueryable();

            if (queryObj.ClassId.HasValue)
            {
                query = query.Where(s => s.ClassSection.ClassId == queryObj.ClassId.Value);
            }

            if (queryObj.ClassSectionId.HasValue)
            {
                query = query.Where(s => s.ClassSectionId == queryObj.ClassSectionId);
            }

            if (!IsNullOrWhiteSpace(queryObj.Search))
            {
                query = query.Where(s =>
                                    s.FirstName.Contains(queryObj.Search) ||
                                    s.LastName.Contains(queryObj.Search) ||
                                    s.Email.Contains(queryObj.Search) ||
                                    s.ClassSection.Name.Contains(queryObj.Search) ||
                                    s.ClassSection.Class.Name.Contains(queryObj.Search));
            }


            var columnsMap = new Dictionary <string, Expression <Func <Student, object> > >
            {
                ["class"]        = s => s.ClassSection.Class.Name,
                ["classSection"] = s => s.ClassSection.Name,
                ["firstName"]    = s => s.FirstName,
                ["lastName"]     = s => s.LastName
            };

            query             = query.ApplyOrdering(queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Example #4
0
        public async Task <QueryResult <Student> > GetStudentsAsync(StudentQuery queryObj)
        {
            var result = new QueryResult <Student>();
            var query  = context.Students.AsQueryable();

            var columnsMap = new Dictionary <string, Expression <Func <Student, object> > >()
            {
                ["FirstName"] = s => s.FirstName,
                ["LastName"]  = s => s.LastName,
                ["School"]    = s => s.School
            };

            query             = query.ApplyOrdering(queryObj, columnsMap);
            result.TotalItems = await query.CountAsync();

            query        = query.ApplyPaging(queryObj);
            result.Items = await query.ToListAsync();

            return(result);
        }
Example #5
0
        public async Task <IEnumerable <StudentModel> > Handle(StudentQuery request, CancellationToken cancellationToken)
        {
            IEnumerable <StudentModel> data;

            if (!string.IsNullOrEmpty(request.searchTerm))
            {
                var resultSet = await _repository.Get(request.searchTerm);

                data = resultSet;
            }
            else
            {
                var resultSet = await _repository.GetAll();

                data = resultSet;
            }

            await _mediator.Publish(new QueryNotification()
            {
                SearchTerm = request.searchTerm
            });

            return(await Task.FromResult(data));
        }
Example #6
0
 public StudentService(AppDbContext context)
 {
     this.context = context;
     query        = new StudentQuery();
 }
Example #7
0
 public Task <IList <StudentSummary> > GetAll([FromBody] StudentQuery query)
 {
     return(_studentRepository.SearchStudent(query));
 }
 public async Task <IEnumerable <Student> > Handle(StudentQuery request, CancellationToken cancellationToken) => DB.GetStudents();