public GeneralAnswerData getCategories() { GeneralAnswerData generalAnswerData = new GeneralAnswerData(); Console.WriteLine("getCategories"); Stream dataStream; WebRequest request; string url = HostName + "?q=webservice/categories&sessionid=" + SessionId; request = WebRequest.Create(Uri.EscapeUriString(url)); request.Method = "GET"; //krequest.KeepAlive = true; request.Timeout = 10000; using (WebResponse response = request.GetResponse()) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(CategoriesResponse)); using (dataStream = response.GetResponseStream()) { CategoriesResponse resp = (CategoriesResponse)serializer.ReadObject(dataStream); generalAnswerData.Categories = resp.Categories; return(generalAnswerData); } } }
public override async Task <CategoriesResponse> GetCategories(UserRequest request, ServerCallContext context) { var categories = await categoryRepository.GetCategories(); var result = new CategoriesResponse() { StatusCode = StatusCode.Ok }; result.CategoryData.Add(categories.Select(o => o.Map())); return(result); }
public async Task <IActionResult> GetCategoriesAsync( CancellationToken ct) { var categories = await _repository.GetCategoriesAsync(ct); var response = new CategoriesResponse { Value = categories.ToArray(), Self = Link.ToCollection(nameof(GetCategoriesAsync)) }; return(Ok(response)); }
public IList <Category> GetCategories() { Uri authLink = new Uri("http://cloud.mm-day.com/Fun/Imagini/Categories"); HttpClientHandler handler = new HttpClientHandler(); var client = new HttpClient(handler); Task <string> resp = client.GetStringAsync(authLink); resp.Wait(); CategoriesResponse categs = CategoriesResponse.FromJson(resp.Result); return(categs.Categories); }
//[Route("GetSubCategoriesByCatId")] //[HttpGet] //public IActionResult GetCatWithSubCatList(Guid id) //{ // try // { // IEnumerable<SubCategoryEntity> subcat = db.SubCategories // .Where(_ => _.IsDeleted != true && _.CategoryId == id) // .ToList(); // return Json(GetCategoriesResponse(categories)); // } // catch (Exception e) // { // return StatusCode(500); // } //} #region Private Region private IEnumerable <CategoriesResponse> GetCategoriesResponse(IEnumerable <CategoryEntity> categories) { return(categories .Select(c => { var response = new CategoriesResponse() { Id = c.Id, Name = c.Name, SubCategories = c.SubCategoryLink.ToList() }; return response; }).ToList()); }
private List <MagazinesResponse> GetAllMagazinesResponses(CategoriesResponse categoriesResponse) { // build a list of categories to make one http call for each in parallel mode var categoryList = new List <string>(); foreach (var category in categoriesResponse.Data) { categoryList.Add(category); } var magazineListResponse = _dataService.GetMagazineResponseAsync(categoriesResponse.Token, categoryList) .GetAwaiter() .GetResult() .ToList(); return(magazineListResponse); }
private async Task <List <(string, string)> > GetCategories(Configuration configuration) { CategoriesApi categoriesApi = new CategoriesApi(configuration); CategoriesResponse categories = await categoriesApi.GetCategoriesAsync("default"); List <(string, string)> categoryStringsToIds = new List <(string, string)>(); foreach (var categoryGroup in categories.CategoryGroups) { string categoryGroupName = categoryGroup.Name; foreach (var category in categoryGroup.Categories) { categoryStringsToIds.Add(($"{categoryGroupName.Trim()}: {category.Name.Trim()}", category.Id !.Value.ToString())); } } return(categoryStringsToIds); }
public IActionResult GetAll(int id, [FromBody] GetCategoriesInput input) { CategoriesResponse response = new CategoriesResponse(); response.status = new Status(); response.status.success = false; try { CategoryManager manager = new CategoryManager(context); response.categories = manager.getAll(id, input.includeAmounts, input.startDate, input.endDate, input.categoryTypeId); response.status.success = true; } catch (Exception exception) { response.status.errorMessage = exception.Message; } return(Json(response)); }
/// <summary> /// Example code to call Rosette API to get a document's (located at given URL) categories. /// Requires Nuget Package: /// rosette_api /// </summary> static void Main(string[] args) { //To use the C# API, you must provide an API key string apikey = "Your API key"; string alturl = string.Empty; //You may set the API key via command line argument: //categories yourapikeyhere if (args.Length != 0) { apikey = args[0]; alturl = args.Length > 1 ? args[1] : string.Empty; } try { CAPI CategoriesCAPI = string.IsNullOrEmpty(alturl) ? new CAPI(apikey) : new CAPI(apikey, alturl); string categories_text_data = @"Sony Pictures is planning to shoot a good portion of the new ""Ghostbusters"" in Boston as well."; //The results of the API call will come back in the form of a Dictionary CategoriesResponse response = CategoriesCAPI.Categories(categories_text_data, null, null, null); Console.WriteLine(response.ContentAsJson); //Rosette API also supports Dictionary inputs //Simply instantiate a new dictionary object with the fields options as keys and inputs as values string categories_url_data = @"http://www.onlocationvacations.com/2015/03/05/the-new-ghostbusters-movie-begins-filming-in-boston-in-june/"; response = CategoriesCAPI.Categories(new Dictionary <object, object>() { { "contentUri", categories_url_data } }); foreach (KeyValuePair <string, string> h in response.Headers) { Console.WriteLine(string.Format("{0}:{1}", h.Key, h.Value)); } Console.WriteLine(response.ToString()); } catch (Exception e) { Console.WriteLine(e.Message); } }
static Category[] ListCategories(string hostname, string sessionid) { Stream dataStream; WebRequest request; Console.WriteLine("### List categories ###"); string url = "http://" + hostname + "/fcgi-bin/finance?q=webservice/categories&sessionid=" + sessionid; request = WebRequest.Create(Uri.EscapeUriString(url)); request.Method = "GET"; WebResponse response = request.GetResponse(); Console.WriteLine("Response:"); DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(CategoriesResponse)); using (dataStream = response.GetResponseStream()) { CategoriesResponse resp = (CategoriesResponse)serializer.ReadObject(dataStream); return(resp.Categories); } }
public object Get(Categories request) { string msg; if (!GetCategoriesValidator.Validate("GET", request, out msg)) { base.Response.StatusCode = (int)HttpStatusCode.BadRequest; return msg; } int pageLimit = 10; int skipResults = 0; if (!request.Limit.IsNullOrEmpty()) { pageLimit = int.Parse(request.Limit); } if (!request.Offset.IsNullOrEmpty()) { skipResults = int.Parse(request.Offset) * ((pageLimit != -1) ? pageLimit : 1); } CategoriesResponse response = new CategoriesResponse(); IMongoQuery searchQuery = Query.And(Query.NE("link.term", "parent"), Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))); if (request.List.EqualsIgnoreCase("poi")) { if (pageLimit == -1) { foreach (var p in MongoDb.POICategories.Find(searchQuery).SetSkip(skipResults)) { FillSubCategories(MongoDb.POICategories, p); response.categories.Add(p); } } else { foreach (var p in MongoDb.POICategories.Find(searchQuery).SetSkip(skipResults).SetLimit(pageLimit)) { FillSubCategories(MongoDb.POICategories, p); response.categories.Add(p); } } } else if (request.List.EqualsIgnoreCase("route")) { if (pageLimit == -1) { foreach (var p in MongoDb.RouteCategories.Find(searchQuery).SetSkip(skipResults)) { FillSubCategories(MongoDb.RouteCategories, p); response.categories.Add(p); } } else { foreach (var p in MongoDb.RouteCategories.Find(searchQuery).SetSkip(skipResults).SetLimit(pageLimit)) { FillSubCategories(MongoDb.RouteCategories, p); response.categories.Add(p); } } } else if (request.List.EqualsIgnoreCase("event")) { if (pageLimit == -1) { foreach (var p in MongoDb.EventCategories.Find(searchQuery).SetSkip(skipResults)) { FillSubCategories(MongoDb.EventCategories, p); response.categories.Add(p); } } else { foreach (var p in MongoDb.EventCategories.Find(searchQuery).SetSkip(skipResults).SetLimit(pageLimit)) { FillSubCategories(MongoDb.EventCategories, p); response.categories.Add(p); } } } return response; }