예제 #1
0
 public IActionResult Search(CourseCatalog.DAL.DTO.SearchCriteria searchCriteria)
 {
     try {
         string vendors       = _dataRepository.Search(searchCriteria);
         string jsonFormatted = JValue.Parse(vendors).ToString(Formatting.Indented);
         return(StatusCode(200, jsonFormatted));
     }
     catch (Exception ex) {
         dynamic response = new ExpandoObject();
         response.ErrorMsg = ex.Message;
         string errMsg = JsonConvert.SerializeObject(response, Formatting.Indented);
         return(BadRequest(errMsg));
     }
 }
        public string Search(CourseCatalog.DAL.DTO.SearchCriteria searchCriteria)
        {
            string jsonInput  = JsonConvert.SerializeObject(searchCriteria, Formatting.None);
            string jsonOutput = string.Empty;
            string spName     = "jsonSearchWebcasts";

            try {
                using (SqlConnection cn = new SqlConnection(conn)) {
                    var cmd = new SqlCommand(cmdText: spName, connection: cn)
                    {
                        CommandType = CommandType.StoredProcedure
                    };
                    cmd.Parameters.AddWithValue(parameterName: "@JsonInput", value: jsonInput);
                    cn.Open();
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        reader.Read();
                        jsonOutput = reader["JsonOutput"].ToString();
                    }
                    reader.Close();
                }

                string target = "Tags" + (char)34 + ":" + (char)34 + "[";

                if (jsonOutput.IndexOf(target) > -1)
                {
                    return(CleanupStringArray(jsonOutput));
                }
                else
                {
                    return(jsonOutput);
                }
            }
            catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine(ex);
                throw;
            }
        }