Пример #1
0
        public RatingDTO GetRating(long id)
        {
            var lawyer  = LawyerRepository.Get(s => s.Id == id, includeProperties: "Reviews,Reviews.User,Reviews.Replies,Reviews.Replies.User").FirstOrDefault();
            var reviews = lawyer.Reviews.Select(r => new ReviewDTO
            {
                Id       = r.Id,
                Rate     = r.Rate,
                Title    = r.Title,
                UserId   = r.UserId,
                UserName = r.User.UserName,
                Name     = r.User.Name,
                NameEn   = r.User.NameEn,
                Replies  = r.Replies?.Select(w => ReplyDTO.ToReviewReplyDTO(w))
            });

            return(new RatingDTO
            {
                LawyerRate = LawyerDTO.CalculateRate(lawyer.Reviews).Value,
                Rate1 = lawyer.Reviews.Where(s => s.Rate == 1).Count(),
                Rate2 = lawyer.Reviews.Where(s => s.Rate == 2).Count(),
                Rate3 = lawyer.Reviews.Where(s => s.Rate == 3).Count(),
                Rate4 = lawyer.Reviews.Where(s => s.Rate == 4).Count(),
                Rate5 = lawyer.Reviews.Where(s => s.Rate == 5).Count(),
                TotalRating = lawyer.Reviews.Count(),
                Reviews = reviews
            });
        }
Пример #2
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);
        }