static void RetrieveTaxaUnit(UserSecurityContext context, string name) { TaxaUnitProviderBase prov = TaxonomyManager.Instance.GetTaxaUnitProvider(context); var taxaUnit = prov.Get(name); foreach (var taxa in taxaUnit) { Console.WriteLine("TaxaUnit: " + taxa.Name + ", " + taxa.Description + ", " + taxa.Identity.Identity); } Console.WriteLine("Retrieve TaxaUnit Successful!"); }
public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { TaxaCommonNameProviderBase cnprovider = TaxonomyManager.Instance.GetTaxaCommonNameProvider(user); TaxaUnitProviderBase uprovider = TaxonomyManager.Instance.GetTaxaUnitProvider(user); JToken token = JsonUtils.GetDataPayload(context.Request); JArray jcommonNames = null; if (cnprovider != null && uprovider != null && token != null) { CompoundIdentity unitId = JsonUtils.ToId(token["unitid"]); TaxaUnit unit = uprovider.Get(unitId); if (unit != null) { IEnumerable <TaxaCommonName> names = cnprovider.GetCommonNamesByTaxa(unit); jcommonNames = Jsonifier.ToJson(names); } if (jcommonNames != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jcommonNames.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }
public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); if (token != null) { if (token["unittypeid"] != null) { GetByTaxaUnitType(JsonUtils.ToId(token["unittypeid"]), user, context, cancel); return; } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("nonLiving", StringComparison.OrdinalIgnoreCase)) { try { GetNonLivingTaxa(user, context, cancel); return; } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("children", StringComparison.OrdinalIgnoreCase)) { try { TaxaUnitProviderBase provider = TaxonomyManager.Instance.GetTaxaUnitProvider(user); CompoundIdentity id = JsonUtils.ToId(JsonUtils.GetDataPayload(context.Request)); JArray junits = null; if (provider != null && id != null) { IEnumerable <TaxaUnit> units = provider.GetChildren(id); junits = Jsonifier.ToJson(units); if (junits != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, junits.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("in", StringComparison.OrdinalIgnoreCase)) { try { TaxaUnitProviderBase provider = TaxonomyManager.Instance.GetTaxaUnitProvider(user); IEnumerable <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request)); JArray junits = null; if (provider != null && ids != null) { IEnumerable <TaxaUnit> units = provider.Get(ids); junits = Jsonifier.ToJson(units); if (junits != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, junits.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }