public IActionResult GetFilteredEntitiesBySport(SearchEntityRequestData _objReqData)
        {
            try
            {
                EsClient_obj = oLayer.CreateConnection();
                int _sportid = 1;

                string result     = string.Empty;
                string searchtext = string.Empty;
                searchtext = _objReqData.EntityText.Trim().ToLower();
                List <SearchQueryModel> _objLstSearchQuery = new List <SearchQueryModel>();
                var responseResult = new List <FilteredEntityForCricket>();
                SearchEntityRequestData _objEntityReqData;
                string jsonData = JsonConvert.SerializeObject(_objReqData);
                _objEntityReqData = JsonConvert.DeserializeObject <SearchEntityRequestData>(jsonData);
                //GetMatchDetails obj = new GetMatchDetails();
                MatchDetail _objMatchDetail = _objEntityReqData.MatchDetails;
                _objMatchDetail.SeriesId = _objEntityReqData.EntityTypeId != 5 ? _objMatchDetail.SeriesId : string.Empty;
                _objMatchDetail.MatchId  = _objEntityReqData.EntityTypeId != 9 ? _objMatchDetail.MatchId : string.Empty;
                if (_objEntityReqData != null)
                {
                    Dictionary <string, string> _columns  = sc.GetColumnForEntity(_objEntityReqData.EntityTypeId);
                    QueryContainer _objNestedQuery        = new QueryContainer();
                    QueryContainer _objNestedQueryRresult = new QueryContainer();
                    IEnumerable <FilteredEntityForCricket> _objFilteredEntityForCricket = new List <FilteredEntityForCricket>();

                    // _objNestedQuery = obj.GetMatchDetailQueryST(_objNestedQuery, _objMatchDetail);
                    //_objNestedQuery = obj.GetPlayerDetailQueryForFilteredEntityBySport(_objNestedQuery, _objEntityReqData.playerDetails, _objMatchDetail.SportID);//GetCricketPlayerDetailQuery(_objEntityReqData.playerDetails, _objNestedBoolQuery);
                    if (!string.IsNullOrEmpty(_objMatchDetail.MatchDate))
                    {
                        //_objNestedQuery= obj.GetEntityBySport(_objNestedQuery, _objMatchDetail, _columns, searchtext);
                    }
                    if (_columns.Count > 0)
                    {
                        List <string> EntityIds   = new List <string>();
                        List <string> EntityNames = new List <string>();
                        foreach (var col in _columns)
                        {
                            EntityIds.Add(col.Key);
                            EntityNames.Add(col.Value);
                        }
                        if (searchtext != "")
                        {
                            var Result = sc.GetFilteredEntitiesBySportResult(_objNestedQuery, EntityIds.ElementAt(0), EntityNames.ElementAt(0), EsClient_obj, searchtext);
                            responseResult = Result;
                        }
                    }
                }
                return(Ok(new { responseText = responseResult }));
                //return Ok();
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
Beispiel #2
0
        public IActionResult GetFilteredEntitiesBySport(SearchEntityRequestData _objReqData)
        {
            searchcricket           sc                 = new searchcricket();
            int                     _sportid           = 1;
            string                  result             = string.Empty;
            string                  searchtext         = string.Empty;
            List <SearchQueryModel> _objLstSearchQuery = new List <SearchQueryModel>();
            var                     responseResult     = new List <FilteredEntityForCricket>();
            SearchEntityRequestData _objEntityReqData;
            string                  jsonData = JsonConvert.SerializeObject(_objReqData);

            _objEntityReqData = JsonConvert.DeserializeObject <SearchEntityRequestData>(jsonData);

            if (_objEntityReqData != null)
            {
                EsClient = oLayer.CreateConnection();
                Dictionary <string, string> _columns = sc.GetColumnForEntity(_objEntityReqData.EntityTypeId);
                _sportid   = _objEntityReqData.SportId;
                searchtext = _objEntityReqData.EntityText.Trim().ToLower();
                MatchDetail _objMatchDetail = _objEntityReqData.MatchDetails;
                _objMatchDetail.SeriesId = _objEntityReqData.EntityTypeId != 5 ? _objMatchDetail.SeriesId : string.Empty;
                _objMatchDetail.MatchId  = _objEntityReqData.EntityTypeId != 9 ? _objMatchDetail.MatchId : string.Empty;

                if (_columns != null && _columns.Count > 0)
                {
                    KeyValuePair <string, string> _column = _columns.FirstOrDefault();
                    //Following query is to search the entire match detail
                    if (_columns.Count > 0)
                    {
                        {
                            List <string> EntityIds   = new List <string>();
                            List <string> EntityNames = new List <string>();
                            foreach (var col in _columns)
                            {
                                EntityIds.Add(col.Key);
                                EntityNames.Add(col.Value);
                            }
                            QueryContainer _objNestedQuery        = new QueryContainer();
                            QueryContainer _objNestedQueryRresult = new QueryContainer();
                            IEnumerable <FilteredEntityForCricket> _objFilteredEntityForCricket = new List <FilteredEntityForCricket>();

                            _objNestedQuery = sc.GetMatchDetailQueryST(_objNestedQuery, _objMatchDetail);
                            _objNestedQuery = sc.GetPlayerDetailQueryForFilteredEntityBySport(_objNestedQuery, _objEntityReqData.playerDetails, _objMatchDetail.SportID);//GetCricketPlayerDetailQuery(_objEntityReqData.playerDetails, _objNestedBoolQuery);
                            if (!string.IsNullOrEmpty(_objMatchDetail.MatchDate))
                            {
                                string dlist = _objMatchDetail.MatchDate;
                                if (dlist.Contains("-"))
                                {
                                    string[] strNumbers = dlist.Split('-');
                                    int      start      = int.Parse(DateTime.ParseExact(strNumbers[0], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyyMMdd"));
                                    int      End        = int.Parse(DateTime.ParseExact(strNumbers[1], "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyyMMdd"));
                                    _objNestedQuery = sc.GetFilteredEntitiesBySport(_objMatchDetail, _objNestedQuery, "1", start, _columns, searchtext);
                                }
                                else
                                {
                                    int date = int.Parse(DateTime.ParseExact(_objMatchDetail.MatchDate, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyyMMdd"));
                                    _objNestedQuery = sc.GetFilteredEntitiesBySport(_objMatchDetail, _objNestedQuery, "2", date, _columns, searchtext);
                                }
                            }
                            //if (_objEntityReqData.EntityTypeId == 5)
                            //{
                            //    var s1 = _objFilteredEntityForCricket.Select(d => new { EntityId = d.GetType().GetProperty(EntityIds.ElementAt(1)).GetValue(d, null), EntityName = d.GetType().GetProperty(EntityNames.ElementAt(1)).GetValue(d, null), IsParentSeries = 1 }).Distinct().ToList();
                            //    var s2 = _objFilteredEntityForCricket.Select(d => new { EntityId = d.GetType().GetProperty(EntityIds.ElementAt(0)).GetValue(d, null), EntityName = d.GetType().GetProperty(EntityNames.ElementAt(0)).GetValue(d, null), IsParentSeries = 0 }).Distinct().ToList();
                            //    var s = s1.Union(s2).Where(r => r.EntityName.ToString() != "" && r.EntityName.ToString().ToLower().Contains(searchtext)).Distinct().OrderBy(r => r.EntityName);
                            //    //result = _objSerializer.Serialize(s);

                            //}
                            //if (_objEntityReqData.EntityTypeId == 3 || _objEntityReqData.EntityTypeId == 4)
                            //{
                            //    var s1 = _objFilteredEntityForCricket.Select(t => new { EntityId = t.Team1Id, EntityName = t.Team1 }).Distinct();
                            //    var s2 = _objFilteredEntityForCricket.Select(t => new { EntityId = t.Team2Id, EntityName = t.Team2 }).Distinct();
                            //    var s = s1.Union(s2).Where(r => r.EntityName.ToString() != "" && r.EntityName.ToLower().Contains(searchtext)).Distinct().OrderBy(r => r.EntityName);
                            //    //result = _objSerializer.Serialize(s);


                            //}
                            //else
                            if (searchtext != "")
                            {
                                //sc.GetFilteredEntitiesBySportResult(_objNestedQuery, EntityIds.ElementAt(0), EntityNames.ElementAt(0),EsClient);
                                //var s = _objFilteredEntityForCricket.Select(d => new { EntityId = d.GetType().GetProperty(EntityIds.ElementAt(0)).GetValue(d, null), EntityName = d.GetType().GetProperty(EntityNames.ElementAt(0)).GetValue(d, null) }).Distinct();
                                var Result = sc.GetFilteredEntitiesBySportResult(_objNestedQuery, EntityIds.ElementAt(0), EntityNames.ElementAt(0), EsClient, searchtext);
                                //result = _objSerializer.Serialize(Result);
                                responseResult = Result;
                            }
                            _objFilteredEntityForCricket = null;
                        }
                    }
                }
            }
            return(Ok(new { responseText = responseResult }));
        }