public IHttpActionResult Dept() { try { IndexRepository dbData = new IndexRepository(dbCxt); IEnumerable <KeyValuePair <string, string> > queryString = Request.GetQueryNameValuePairs(); string DeptValue = queryString.Where(nv => nv.Key == "dept_key").Select(nv => nv.Value).FirstOrDefault(); //strip off last character if a slash //if pDeptKey is null then return all records if (String.IsNullOrEmpty(DeptValue)) { var dataValue = dbData.GetIndices(); return(Ok(dbData.GetIndices())); } int pDeptKey; Int32.TryParse(DeptValue, out pDeptKey); return(Ok(dbData.GetIndices_ByDept(pDeptKey))); } catch (Exception exError) { return(BadRequest((new Error(0, exError.Message, "IndicesByOwner").ToString()))); } }