public IEnumerable <LectionViewModel> Search([FromQuery] string name = null, [FromQuery] int?courseId = null, [FromQuery] DateTime?date = null) { var predicateBuilder = new СonjunctionPredicateBuilder(); if (name != null) { predicateBuilder.AddPropertyEqComparation((LectionViewModel x) => x.Name, name); } if (courseId != null) { predicateBuilder.AddPropertyEqComparation((LectionViewModel x) => x.CourseId, courseId.Value); } if (date != null) { predicateBuilder.AddPropertyEqComparation((LectionViewModel x) => x.Date, date.Value); } if (!predicateBuilder.IsEmpty) { return(_appService.List <LectionViewModel>((Expression <Predicate <LectionViewModel> >)predicateBuilder.Lambda)); } else { return(_appService.List <LectionViewModel>()); } }
public IEnumerable <StudentViewModel> Search([FromQuery] string name = null, [FromQuery] string email = null, [FromQuery] string phone = null) { var predicateBuilder = new СonjunctionPredicateBuilder(); if (name != null) { predicateBuilder.AddPropertyEqComparation((StudentViewModel x) => x.Name, name); } if (email != null) { predicateBuilder.AddPropertyEqComparation((StudentViewModel x) => x.Email, email); } if (phone != null) { predicateBuilder.AddPropertyEqComparation((StudentViewModel x) => x.Email, phone); } if (!predicateBuilder.IsEmpty) { return(_appService.List((Expression <Predicate <StudentViewModel> >)predicateBuilder.Lambda)); } else { return(_appService.List <StudentViewModel>()); } }
public IReadOnlyCollection <MarkViewModel> GetMarks(int?studentId = null, int?courseId = null, int?lectionId = null) { var predicateBuilder = new СonjunctionPredicateBuilder(); predicateBuilder.AddArg <Mark>(); if (lectionId.HasValue) { predicateBuilder.AddArgWithPropertyEqComparation((Lection l) => l.Id, lectionId.Value); } else { predicateBuilder.AddArg <Lection>(); } if (courseId.HasValue) { predicateBuilder.AddArgWithPropertyEqComparation((Course c) => c.Id, courseId.Value); } else { predicateBuilder.AddArg <Course>(); } predicateBuilder.AddArg <StudentCourse>(); if (studentId.HasValue) { predicateBuilder.AddArgWithPropertyEqComparation((Student c) => c.Id, studentId.Value); } else { predicateBuilder.AddArg <Student>(); } var predicate = (predicateBuilder.IsEmpty ? null : (predicateBuilder.Lambda)) as Expression <Func <Mark, Lection, Course, StudentCourse, Student, bool> >; return(_repository.InnerJoin((Mark m, Lection l, Course c, StudentCourse sc, Student s) => new MarkViewModel() { Id = m.Id, Value = MarkValueAsString(m.Value), Lection = _mapper.Map <Lection, LectionViewModel>(l), Course = _mapper.Map <Course, CourseViewModel>(c), Student = _mapper.Map <Student, StudentViewModel>(s) }, (m, l, c, sc, s) => m.LectionId == l.Id && l.CourseId == c.Id && c.Id == sc.CourseId && sc.StudentId == s.Id, predicate).ToList()); }