public JsonResult Search(SearchMerchantModel model) { model.LanguageId = ACultureHelper.GetLanguageID; var result = this._merchantService.Search(model); return(this.Json(new { rows = result.Data, total = result.Data.TotalCount }, JsonRequestBehavior.AllowGet)); }
public ResultModel Search(SearchMerchantModel model) { return(this._database.RunQuery(db => { var result = new ResultModel(); var q = db.YH_MerchantInfo.Query() .LeftJoin(db.YH_User, UserID: db.YH_MerchantInfo.MerchantID) .LeftJoin(db.THArea_lang) .On(db.THArea_lang.THAreaID == db.YH_MerchantInfo.AreaID && db.THArea_lang.LanguageID == model.LanguageId) .Select( db.YH_MerchantInfo.MerchantID, db.YH_MerchantInfo.ShopName, db.YH_MerchantInfo.MerchantType, db.YH_MerchantInfo.LeasingManager, db.YH_MerchantInfo.LeasingPhone, db.YH_MerchantInfo.BusinessContacter, db.YH_MerchantInfo.BusinessTel, db.YH_MerchantInfo.CreateBy, db.YH_MerchantInfo.CreateDT, db.YH_MerchantInfo.AuditBy, db.YH_MerchantInfo.AuditDT, db.YH_MerchantInfo.AuditRemark , db.YH_User.IsLock , db.THArea_lang.AreaName ) .OrderByDescending(db.YH_MerchantInfo.MerchantID); result.Data = new SimpleDataPagedList <MerchantModel>(q, model.PagedIndex, model.PagedSize); return result; })); }
public override async Task <SearchMerchantsResponse> SearchMerchants(SearchMerchantsRequest request, ServerCallContext context) { context.Status = new Status(StatusCode.OK, $"OK"); var rows = await _merchantQueries.SearchMerchants(request.Lat, request.Lng, request.Miles, request.Location, request.Location); var response = new SearchMerchantsResponse { DisplayLocation = request.Location }; if (rows != null) { try { var dict_merchants = new Dictionary <int, SearchMerchantModel>(); foreach (var row in rows) { var m = (Merchant)row.m; var mi = (MerchantImage)row.mi; if (!dict_merchants.ContainsKey(m.ID)) { var merchant = new SearchMerchantModel { ID = m.ID, Name = m.Name ?? string.Empty, Description = m.Description ?? string.Empty, CallToAction = m.CallToAction ?? string.Empty, ShortDescription = m.ShortDescription ?? string.Empty, WebsiteUrl = m.WebsiteUrl ?? string.Empty, Street1 = m.Street1 ?? string.Empty, Street2 = m.Street2 ?? string.Empty, StateAbbreviation = m.StateAbbreviation ?? string.Empty, City = m.City ?? string.Empty, Zip = m.Zip ?? string.Empty, Latitude = m.Latitude, Longitude = m.Longitude, MerchantTypeID = m.MerchantTypeID, MerchantTypeName = m.MerchantType?.Name ?? string.Empty, MilesAway = 0, DefaultImageUrl = string.Empty, Location = string.Empty, DistanceAway = string.Empty }; merchant.MilesAway = request.Lat != 0 && request.Lng != 0 ? m.HaversineDistance(request.Lat, request.Lng) : 0.0; dict_merchants.Add(m.ID, merchant); } if (mi != null && !string.IsNullOrEmpty(mi.ImageUrl) && string.IsNullOrEmpty(dict_merchants[m.ID].DefaultImageUrl)) { dict_merchants[m.ID].DefaultImageUrl = mi.ImageUrl; } } if (string.IsNullOrWhiteSpace(request.Keyword)) { response.Merchants.AddRange(dict_merchants.Values); } else { //TODO: improve search response.Merchants.AddRange(dict_merchants.Values .Where(m => m.Name.ToLower().Contains(request.Keyword.ToLower()))); } } catch (System.Exception e) { throw e; } } return(response); }