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 }); }
public IHttpActionResult Put(LawyerDTO lawyer) { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new LawyerContext()) { var existingLawyer = ctx.Lawyers.Where(l => l.Id == lawyer.Id) .FirstOrDefault <Lawyer>(); if (existingLawyer != null) { existingLawyer.Name = lawyer.Name; existingLawyer.Surname = lawyer.Surname; existingLawyer.Initials = lawyer.Initials; existingLawyer.DateOfBirth = lawyer.DateOfBirth; existingLawyer.Email = lawyer.Email; existingLawyer.Gender_id = lawyer.Gender_id; existingLawyer.Title_id = lawyer.Title_id; ctx.SaveChanges(); } else { return(NotFound()); } } return(Ok()); }
public IHttpActionResult GetAllLawyersByID(int lid) { LawyerDTO lawyer = null; using (var ctx = new LawyerContext()) { lawyer = ctx.Lawyers.Include("Name") .Where(l => l.Id == lid) .Select(l => new LawyerDTO() { Id = l.Id, Name = l.Name, Surname = l.Surname, Initials = l.Initials, DateOfBirth = l.DateOfBirth, Email = l.Email, Gender_id = (short)l.Gender_id, Title_id = (short)l.Title_id }).FirstOrDefault <LawyerDTO>(); } if (lawyer == null) { return(NotFound()); } return(Ok(lawyer)); }
public void UpdateLawyer(LawyerDTO lawyer) { var law = LawyerRepository.Get(lawyer.Id); law.Certificates = lawyer.Certificates; law.Description = lawyer.Description; law.CertificatesEn = lawyer.CertificatesEn; law.DescriptionEn = lawyer.DescriptionEn; law.Fees = lawyer.Fees; law.IsOnline = lawyer.IsOnline; law.Rate = lawyer.Rate; law.SpecializationId = lawyer.SpecializationId; law.UserId = lawyer.UserId; law.ModifiedDate = lawyer.ModifiedDate.HasValue ? lawyer.ModifiedDate.Value : DateTime.Now; law.ExperienceId = lawyer.ExperienceId; law.VideoURL = lawyer.VideoURL; LawyerRepository.Update(law); }
public int InsertLawyer(LawyerDTO lawyer) { LawyerRepository.Insert(LawyerDTO.ToLawyer(lawyer)); return(LawyerRepository.Get(s => s.UserId == lawyer.UserId).First().Id); }
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()); } }
public IEnumerable <LawyerDTO> GetLawyers() { return(LawyerRepository.Get(s => s.SpecializationId != null && s.Fees != null && s.Rate != null). Select(s => LawyerDTO.ToLawyerDTO(s))); }
//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); }