public ActionResult <List <AppointmentType> > AppointmentType(bool?isActive = true, bool?excludeUnavailability = true)
        {
            List <AppointmentType> Result = new List <AppointmentType>();
            var predicate = PredicateBuilder.New <AG_S_SERVICE>(true);

            if (isActive.HasValue)
            {
                if (isActive.Value)
                {
                    predicate = predicate.And(E => (E.DT_START == null || E.DT_START <= DateTime.Today) && ((E.DT_END == null) || E.DT_END >= DateTime.Today));
                }
                else
                {
                    predicate = predicate.And(E => !((E.DT_START == null || E.DT_START <= DateTime.Today) && ((E.DT_END == null) || E.DT_END >= DateTime.Today)));
                }
            }

            if (excludeUnavailability.GetValueOrDefault(true))
            {
                string[] unavailabilityServiceCodes = FoxDataService.GetUnavailabilityServiceCodes(null);
                predicate = predicate.And(E => !unavailabilityServiceCodes.Contains(E.SERVICE_TYPE_CODE));
            }

            foreach (AG_S_SERVICE item in DBContext.AG_S_SERVICE.Where(predicate))
            {
                AppointmentType model = EntityMapper.Map <AppointmentType, AG_S_SERVICE>(DBContext, item);
                model.ServiceTypeDescription = item.AG_S_SERVICE_TYPE?.SERVICE_TYPE_DESCR;
                Result.Add(model);
            }

            return(Result);
        }
        public ActionResult <IEnumerable <AppointmentListItem> > Shop(string id, string serviceCodes, string statusCodes, string employeeCodes, DateTime?appointmentDate, int?MaxResultsCount)
        {
            DateTime MinSQLDateTime           = new DateTime(1753, 1, 1);
            List <AppointmentListItem> Result = new List <AppointmentListItem>();
            DateTime AppDate = appointmentDate.GetValueOrDefault(DateTime.Today);

            MaxResultsCount = MaxResultsCount.GetValueOrDefault(Settings.Value.MaxQueryResult);
            if (AppDate <= MinSQLDateTime)
            {
                AppDate = MinSQLDateTime;
            }
            string[] unavailabilityServiceCodes = FoxDataService.GetUnavailabilityServiceCodes(id);

            var predicate = PredicateBuilder.New <AG_B_APPOINTMENT>();

            predicate = predicate.And(E => E.APPOINTMENT_SHOP_CODE == id && E.DT_APPOINTMENT.Date == AppDate.Date && !unavailabilityServiceCodes.Contains(E.SERVICE_CODE));

            if (!string.IsNullOrWhiteSpace(serviceCodes))
            {
                string[] codes = serviceCodes.Split("|");
                predicate = predicate.And(E => codes.Contains(E.SERVICE_CODE));
            }

            if (!string.IsNullOrWhiteSpace(statusCodes))
            {
                string[] codes = statusCodes.Split("|");
                predicate = predicate.And(E => codes.Contains(E.STATUS_CODE));
            }

            if (!string.IsNullOrWhiteSpace(employeeCodes))
            {
                string[] codes = employeeCodes.Split("|");
                predicate = predicate.And(E => codes.Contains(E.EMPLOYEE_CODE));
            }

            foreach (AG_B_APPOINTMENT Item in DBContext.AG_B_APPOINTMENT.Where(predicate).OrderByDescending(E => E.DT_APPOINTMENT).Take(MaxResultsCount.Value))
            {
                AppointmentListItem ListItem = EntityMapper.Map <AppointmentListItem, AG_B_APPOINTMENT>(DBContext, Item, Item.AG_B_APPOINTMENT_EXT_AUS);
                Result.Add(ListItem);
            }
            return(Result);
        }