public CollectionResult <Appointment> GetAppointmentsByParams(AppointmentsFilterParams parameters)
        {
            var appointments = GetAllAppointments();

            FillAppointmentsQueryParams(parameters);

            appointments = appointments.Where(parameters.Expression);

            var totalCount = appointments.Count();

            var result = appointments
                         .OrderByDescending(x => x.Date)
                         .Skip(parameters.Skip)
                         .Take(parameters.Take)
                         .AsNoTracking()
                         .ToList();

            var appointmentsResult = new CollectionResult <Appointment>
            {
                Collection = result,
                TotalCount = totalCount
            };

            return(appointmentsResult);
        }
        private void FillAppointmentsQueryParams(AppointmentsFilterParams filterParams)
        {
            var predicate = PredicateBuilder.New <Appointment>(t => t.ResidentId == filterParams.ResidentId);

            if (filterParams.StartDate.HasValue && filterParams.EndDate.HasValue)
            {
                predicate = predicate.And(t => t.Date >= filterParams.StartDate.Value && t.Date <= filterParams.EndDate.Value);
            }

            filterParams.Expression = predicate;
        }
Exemplo n.º 3
0
        public CollectionResult <AppointmentDto> GetAppointmentsByParams(AppointmentsFilterParams filterParams)
        {
            var items = _unitOfWork.AppointmentRepository.GetAppointmentsByParams(filterParams);

            var result = new CollectionResult <AppointmentDto>
            {
                TotalCount = items.TotalCount,
                Collection = AutoMapper.Mapper.Map <IEnumerable <Appointment>, List <AppointmentDto> >(items.Collection)
            };

            return(result);
        }
        public IActionResult GetAppointments([FromBody] AppointmentsFilterParams filterParams)
        {
            var appointments = _appointmentService.GetAppointmentsByParams(filterParams);

            return(Json(JsonResultData.Success(appointments)));
        }