From f10e09a94bffd443358ddc59324b77258a4c7b7f Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Sun, 17 Nov 2024 17:42:53 +0300 Subject: [PATCH] Trying to make csharp like the usage of uow in tourservice --- .../EntertaimentService/EntertaimentService.cs | 4 ++-- TourService/Services/TourService/TourService.cs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/EntertaimentService/Services/EntertaimentService/EntertaimentService.cs b/EntertaimentService/Services/EntertaimentService/EntertaimentService.cs index 1d79717..72af4d3 100644 --- a/EntertaimentService/Services/EntertaimentService/EntertaimentService.cs +++ b/EntertaimentService/Services/EntertaimentService/EntertaimentService.cs @@ -64,7 +64,7 @@ public IQueryable GetEntertaiments(GetEntertaimentsRequest getE IQueryable entertaiments; if(getEntertaiments.Categories!=null) { - var entertainments = _unitOfWork.Entertaiments.GetAll() + entertainments = _unitOfWork.Entertaiments.GetAll() .Where(e => _unitOfWork.EntertaimentCategories.GetAll() .Where(ec => getEntertaiments.Categories.Contains(ec.CategoryId)) @@ -81,7 +81,7 @@ public IQueryable GetEntertaiments(GetEntertaimentsRequest getE } else { - var entertainments = _unitOfWork.Entertaiments.GetAll() + entertainments = _unitOfWork.Entertaiments.GetAll() .Where(e => e.Rating >= getEntertaiments.MinimalRating && e.Rating <= getEntertaiments.MaximalRating && e.Price >= getEntertaiments.MinimalPrice && e.Price <= getEntertaiments.MaximalPrice && diff --git a/TourService/Services/TourService/TourService.cs b/TourService/Services/TourService/TourService.cs index 659338f..58ea89f 100644 --- a/TourService/Services/TourService/TourService.cs +++ b/TourService/Services/TourService/TourService.cs @@ -125,23 +125,22 @@ public IQueryable GetTours(GetToursRequest getTours) { tours = _unitOfWork.Tours.GetAll() .Where(t => - _unitOfWork.TourCategories.GetAll() - .Where(tc => getTours.Categories.Contains(tc.CategoryId)) - .Select(tc => tc.TourId) - .Contains(t.Id) - ) - .Where(t => t.Rating >= getTours.MinimalRating && t.Rating <= getTours.MaximalRating) - .Where(t => t.Price >= getTours.MinimalPrice && t.Price <= getTours.MaximalPrice) - .Distinct() + t.Rating >= getTours.MinimalRating && + t.Rating <= getTours.MaximalRating && + t.Price >= getTours.MinimalPrice && + t.Price <= getTours.MaximalPrice && + _unitOfWork.TourCategories.GetAll(new FindOptions()) + .Any(tc => tc.TourId == t.Id && getTours.Categories.Contains(tc.CategoryId))) .Skip((getTours.Page - 1) * 10) .Take(10) .ToList(); + } else if(getTours.TourTags!=null) { tours = _unitOfWork.Tours.GetAll() .Where(t => - _unitOfWork.TourTags.GetAll() + _unitOfWork.TourTags.GetAll(new FindOptions()) .Where(tt => getTours.TourTags.Contains(tt.TagId)) .Select(tt => tt.TourId) .Contains(t.Id)