public IActionResult GetQueries(IQueryCollection queries) { object specsInfo = null; switch (queries.First().Key.ToLower()) { case "ram": { if (!int.TryParse(queries["deviceId"], out int id)) { return(NotFound()); } if (id <= 0) { return(NotFound()); } if (!_service.GetByDeviceId(id, out specsInfo)) { return(NotFound()); } } break; default: return(NotFound()); } return(Ok(specsInfo)); }
public IActionResult GetQueries(IQueryCollection queries) { object deviceinfo = null; //var error = new ErrorNotFound(); switch (queries.First().Key.ToLower()) { case "brand": { if (!int.TryParse(queries["controlNumber"], out int id)) { return(NotFound()); } if (id <= 0) { return(NotFound()); } if (!_deviceService.GetByControlNumber(id, out deviceinfo)) { return(NotFound()); } } break; default: return(NotFound()); } return(Ok(deviceinfo)); }
private List <IFilterDescriptor> GetFilterData(IQueryCollection args) { IEnumerable <IFilterDescriptor> filters = new List <IFilterDescriptor>(); var filterKeys = args.Where(o => o.Key.Contains("filterModel")) .GroupBy(o => o.Key.Substring(o.Key.IndexOf("[") + 1, o.Key.IndexOf("]") - o.Key.IndexOf("[") - 1)) .Select(o => o.Key).ToArray(); foreach (var key in filterKeys) { string filterType = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][filterType]")).Value.ToString(); string type = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][type]")).Value.ToString(); var conditions = args.Where(o => o.Key.Contains($"filterModel[{key}][condition")).GroupBy(o => o.Key.Substring(o.Key.IndexOf("[condition"), 12)).ToArray(); if (conditions.Any()) { string oprt = args.First(o => o.Key.Contains($"filterModel[{key}][operator]")).Value.ToString(); var compositeFilter = new CompositeFilterDescriptor(); IEnumerable <IFilterDescriptor> filterSubItems = new FilterDescriptorCollection(); var maxConditionCount = Math.Min(conditions.Count(), 9); for (var i = 0; i < maxConditionCount; i++) { string condetionFilterType = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][condition{i + 1}][filterType]")).Value.ToString(); string conditionType = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][condition{i + 1}][type]")).Value.ToString(); string conditionFilter = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][condition{i + 1}][filter]")).Value.ToString(); string conditionFilterTo = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][condition{i + 1}][filterTo]")).Value.ToString(); //toto should be correct filterSubItems = AddFilterDescriptor(filterSubItems, key, condetionFilterType, conditionType, conditionFilter, conditionFilterTo); } var collection = new FilterDescriptorCollection(); collection.AddRange(filterSubItems.ToList()); compositeFilter.FilterDescriptors = collection; compositeFilter.LogicalOperator = (oprt == "AND" ? FilterCompositionLogicalOperator.And : FilterCompositionLogicalOperator.Or); filters = filters.Concat(new List <IFilterDescriptor>() { compositeFilter }); } else { string filter = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][filter]")).Value.ToString(); string filterTo = args.FirstOrDefault(o => o.Key.Contains($"filterModel[{key}][filterTo]")).Value.ToString(); filters = AddFilterDescriptor(filters, key, filterType, type, filter, filterTo); } } return(filters.ToList()); }
private static List <SortDescriptor> GetSortData(IQueryCollection args) { List <SortDescriptor> orderByItems = new List <SortDescriptor>(); var s = args.Where(o => o.Key.Contains("sortModel")); int c = s.Count() / 2; for (var i = 0; i < c; i++) { string colId = args.FirstOrDefault(o => o.Key.Contains($"sortModel[{i}][colId]")).Value.ToString(); string sort = args.First(o => o.Key.Contains($"sortModel[{i}][sort]")).Value.ToString(); if (!string.IsNullOrEmpty(colId) && !string.IsNullOrEmpty(sort)) { orderByItems.Add(new SortDescriptor() { Member = string.Concat(colId.Split(new[] { '-', '_' }, StringSplitOptions.RemoveEmptyEntries) .Select(word => word.Substring(0, 1).ToUpper() + word.Substring(1).ToLower())), SortDirection = sort.ToUpper() == "ASC" ? System.ComponentModel.ListSortDirection.Ascending : System.ComponentModel.ListSortDirection.Descending }); } } return(orderByItems); }
public static URLData GetData(HttpContext context) { string urlPath = context.Request.Path; IQueryCollection queryData = context.Request.Query; string fileName = string.Empty; string folderPath = string.Empty; if (queryData.Count > 0) { fileName = queryData.First().Value + ".json"; folderPath = urlPath; } else { if (urlPath.LastIndexOf('/') < 0) { throw new BadUrlFormatException("No file found in URL"); } fileName = urlPath.Substring(urlPath.LastIndexOf('/')); if (fileName.Length == 0) { throw new BadUrlFormatException("File name cannot be found"); } fileName = fileName + ".json"; folderPath = urlPath.Substring(0, urlPath.LastIndexOf('/')); if (folderPath.Length == 0) { throw new BadUrlFormatException("Directory name cannot be found"); } } return(new URLData(folderPath, fileName)); }