public IActionResult SearchVenue([FromQuery] RestaurantSearchModel searchModel) { var result = _restaurantService.Search(searchModel); if (result.ResponseData.Data.Count > 0) { string UniqueIdSerial = string.Empty; UniqueIdSerial = string.Join(',', result.ResponseData.Data.Select(x => x.UniqueId)); return(Ok(result)); } return(NotFound(result)); }
public IActionResult Search([FromQuery] RestaurantSearchModel searchModel) { //LogHelper.InsertLog() var result = _restaurantService.Search(searchModel); if (result.ResponseData.Data.Count > 0) { string UniqueIdSerial = string.Empty; UniqueIdSerial = string.Join(',', result.ResponseData.Data.Select(x => x.UniqueId)); //LogHelper.InsertLog("RestaurantsController", "SearchCountRestaurant",LogType.Info , UniqueIdSerial, "Writing for counting found out seaching of retaurant"); } return(Ok(result)); }
public BaseResponse <PageListPortal <RestaurantSearchViewModel> > Search(RestaurantSearchModel searchModel) { try { if (searchModel == null) { return(BaseResponse <PageListPortal <RestaurantSearchViewModel> > .NotFound(new PageListPortal <RestaurantSearchViewModel>(Enumerable.Empty <RestaurantSearchViewModel>().AsQueryable(), searchModel.PageIndex, searchModel.PageSize), message : "searchModel variable is null", fullMsg : "")); } searchModel.BusinessDay = searchModel.BusinessDay ?? ""; var sortString = !string.IsNullOrEmpty(searchModel.SortString) ? searchModel.SortString : "RestaurantName DESC"; searchModel.PageIndex = searchModel.PageIndex > 0 ? searchModel.PageIndex : 1; searchModel.PageSize = searchModel.PageSize > 0 ? searchModel.PageSize : 10; string searchCity = string.IsNullOrWhiteSpace(searchModel.City) ? "\"\"" : "\"" + searchModel.City.Trim() + "\""; string searchZoneDistrict = string.IsNullOrWhiteSpace(searchModel.ZoneDistrict) ? "\"\"" : "\"" + searchModel.ZoneDistrict.Trim() + "\""; string searchRestaurantName = string.IsNullOrWhiteSpace(searchModel.RestaurantName) ? "\"\"" : "\"" + searchModel.RestaurantName.Trim() + "\""; string extendFilter = string.Empty; #region Attribute define var listCuisine = new List <int>(); var listSuitable = new List <int>(); var listServing = new List <int>(); if (searchModel.AttributeFid != null && searchModel.AttributeFid.Count > 0) { List <AttributeValueModel> attributeList = new List <AttributeValueModel>(); foreach (string attItem in searchModel.AttributeFid) { if (!string.IsNullOrEmpty(attItem)) { string[] arrResponse = attItem.Split('_'); if (arrResponse.Count() > 1) { int categoryId = string.IsNullOrEmpty(arrResponse[0]) != true?int.Parse(arrResponse[0]) : 0; AttributeValueModel attributeItem = new AttributeValueModel { CategoryId = string.IsNullOrEmpty(arrResponse[0]) != true?int.Parse(arrResponse[0]) : 0, AttributeValue = string.IsNullOrEmpty(arrResponse[1]) != true?int.Parse(arrResponse[1]) : 0 }; attributeList.Add(attributeItem); } } } listCuisine = (attributeList.Where(k => k.CategoryId == (int)AttributeEnum.Cuisines).Select(x => x.AttributeValue)).ToList(); listServing = (attributeList.Where(k => k.CategoryId == (int)AttributeEnum.Servings).Select(x => x.AttributeValue)).ToList(); listSuitable = (attributeList.Where(k => k.CategoryId == (int)AttributeEnum.SuitableFor).Select(x => x.AttributeValue)).ToList(); } #endregion var query = (_searchContext.Restaurants .Where( k => k.Deleted == false && k.ActiveForOperation == true && (listCuisine.Count() == 0 || (listCuisine.Count() > 0 && k.AttributeValues.Any(l => l.AttributeCategoryFid == (int)AttributeEnum.Cuisines && listCuisine.Contains(l.AttributeFid)))) && (listServing.Count() == 0 || (listServing.Count() > 0 && k.AttributeValues.Any(l => l.AttributeCategoryFid == (int)AttributeEnum.Servings && listServing.Contains(l.AttributeFid)))) && (listSuitable.Count() == 0 || (listSuitable.Count() > 0 && k.AttributeValues.Any(l => l.AttributeCategoryFid == (int)AttributeEnum.SuitableFor && listSuitable.Contains(l.AttributeFid)))) && (string.IsNullOrWhiteSpace(searchModel.City) || (!string.IsNullOrWhiteSpace(searchModel.City) && k.City == searchModel.City.Trim())) && (string.IsNullOrWhiteSpace(searchModel.ZoneDistrict) || (!string.IsNullOrWhiteSpace(searchModel.ZoneDistrict) && k.ZoneDistrict == searchModel.ZoneDistrict.Trim())) && (string.IsNullOrWhiteSpace(searchModel.RestaurantName) || (!string.IsNullOrWhiteSpace(searchModel.RestaurantName) && k.RestaurantName.StartsWith(searchModel.RestaurantName.Trim()))) //&& (k.ServingDining == searchModel.ServingType ) .Select(k => new RestaurantSearchViewModel() { Id = k.Id , UniqueId = k.UniqueId , RestaurantName = k.RestaurantName , IsBusinessDay = _searchContext.GetfnIsBusinessDayOperation(k.Id, searchModel.BusinessDay.Trim() ?? "") , CuisineName = _searchContext.GetCuisines(k.Id, 1) ?? "" , City = k.City ?? "" , ZoneDistrict = k.ZoneDistrict ?? "" , Country = k.Country ?? "" , StartingPrice = k.StartingPrice , CultureCode = k.CultureCode ?? "" , CurrencyCode = k.CurrencyCode ?? "" , FileStreamId = _searchContext.GetfnRestaurantImageIDVal(k.Id, 4), ServingDining = k.ServingDining, ServingVenue = k.ServingVenue })).OrderBy(sortString); return(BaseResponse <PageListPortal <RestaurantSearchViewModel> > .Success(new PageListPortal <RestaurantSearchViewModel>(query, searchModel.PageIndex, searchModel.PageSize))); } catch (Exception ex) { return(BaseResponse <PageListPortal <RestaurantSearchViewModel> > .InternalServerError(new PageListPortal <RestaurantSearchViewModel>(Enumerable.Empty <RestaurantSearchViewModel>().AsQueryable(), searchModel.PageIndex, searchModel.PageSize), message : ex.Message, fullMsg : ex.StackTrace)); } }