示例#1
0
 public IEnumerable <LawyerDTO> GetLawyers()
 {
     return(LawyerRepository.Get(s => s.SpecializationId != null &&
                                 s.Fees != null && s.Rate != null).
            Select(s => LawyerDTO.ToLawyerDTO(s)));
 }
示例#2
0
        public LawyerDTO GetLawyer(long id)
        {
            if (id != 0)
            {
                var lawyer = LawyerRepository.Get(s => s.Id == id, includeProperties: "Experience,Specialization,User,Reviews,Reviews.User").Select(l => LawyerDTO.ToLawyerDTO(l)).FirstOrDefault();
                lawyer.Appointments = lawyerAppointmentService.GetGroupedAppointments(lawyer.Id);
                if (lawyer.Appointments == null || lawyer.Appointments.Count() == 0)
                {
                    lawyer.Appointments = new List <AppointmentGroupedDTO> {
                        new AppointmentGroupedDTO {
                            DateTxt = ""
                        }
                    };
                }

                return(lawyer);
            }
            else
            {
                return(new LawyerDTO());
            }
        }
示例#3
0
        //public void DeleteLawyer(long id)
        //{
        //    Lawyer Lawyer = GetLawyer(id);
        //    LawyerRepository.Delete(Lawyer);
        //}


        public IEnumerable <LawyerDTO> GetLawyers(int ServiceId, string Name, int Specialization, Gender?Gender, List <int> Rating, float minFees, float maxFees, List <int> Prices, bool?isOnline, List <int> Experiences)
        {
            Expression <Func <Lawyer, bool> > filter = null;

            filter = s => s.SpecializationId != null && s.Fees != null && s.Rate != null;


            if (!string.IsNullOrEmpty(Name) && Specialization > 0)
            {
                Expression <Func <Lawyer, bool> > filterToAppend = s => s.User.Name.ToLower().Contains(Name.ToLower()) && s.SpecializationId == Specialization;
                filter = filter.And(filterToAppend);
            }
            else
            {
                if (!string.IsNullOrEmpty(Name))
                {
                    filter = filter.And(s => s.User.Name.ToLower().Contains(Name.ToLower()));
                }

                if (Specialization > 0)
                {
                    filter = filter.And(s => s.SpecializationId == Specialization);
                }
            }

            if (ServiceId > 0)
            {
                filter = filter.And(s => s.Services.Any(a => a.ServiceId == ServiceId));
            }

            if (Gender != null)
            {
                filter = filter.And(s => s.User.Gender == Gender);
            }

            if (isOnline.HasValue)
            {
                if (isOnline.Value)
                {
                    filter = filter.And(s => s.ModifiedDate.AddMinutes(20) >= DateTime.Now);
                }
                else
                {
                    filter = filter.And(s => s.ModifiedDate.AddMinutes(20) < DateTime.Now);
                }
            }

            if (Rating != null && Rating.Count > 0)
            {
                filter = filter.And(s => Rating.Contains(LawyerDTO.CalculateRate(s.Reviews).Value));
            }

            if (minFees > 0)
            {
                filter = filter.And(s => s.Fees >= minFees);
            }

            if (maxFees > 0)
            {
                filter = filter.And(s => s.Fees <= maxFees);
            }

            if (Prices != null && Prices.Count > 0)
            {
                var lst = new List <PriceRange>();
                foreach (var item in Prices)
                {
                    lst.Add(PriceRangeRepository.Get(item));
                }
                lst    = lst.OrderBy(s => s.From).ToList();
                filter = filter.And(s => s.Fees >= lst.First().From&& s.Fees <= lst.Last().To);
            }

            if (Experiences != null && Experiences.Count > 0)
            {
                //Expression<Func<Lawyer, bool>> Expfilter = null;

                //foreach (var item in Experiences)
                //{
                //    if (Expfilter == null)
                //        Expfilter = s => s.ExperienceId == item;
                //    else
                //        Expfilter=Expfilter.a
                //}

                filter = filter.And(s => Experiences.Contains(s.ExperienceId.Value));
            }


            var res = LawyerRepository.Get(filter, includeProperties: "Experience,Specialization,User,Reviews,Reviews.User,Services").Select(s => LawyerDTO.ToLawyerDTO(s)).ToList();

            foreach (var item in res)
            {
                item.Appointments = lawyerAppointmentService.GetGroupedAppointments(item.Id);
                if (item.Appointments == null || item.Appointments.Count() == 0)
                {
                    item.Appointments = new List <AppointmentGroupedDTO> {
                        new AppointmentGroupedDTO {
                            DateTxt = ""
                        }
                    };
                }
            }

            return(res);
        }