private static void GetBySiteAndScheme(CompoundIdentity site_id, CompoundIdentity scheme_id, UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { SiteAliasProviderBase provider = SiteManager.Instance.GetSiteAliasProvider(user); SiteAliasScheme scheme = SiteManager.Instance.GetSiteAliasSchemeProvider(user).Get(scheme_id); if (provider != null && scheme != null && site_id != null) { IEnumerable <SiteAlias> aliases = provider.Get(site_id, scheme); JArray jaliases = Jsonifier.ToJson(aliases); if (jaliases != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jaliases.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } }
private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { SiteAliasSchemeProviderBase provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null) { IEnumerable <SiteAliasScheme> schemes = provider.Get(); JArray jschemes = Jsonifier.ToJson(schemes); if (jschemes != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jschemes.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } }
private static void GetByName(string name, UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { SiteAliasProviderBase provider = SiteManager.Instance.GetSiteAliasProvider(user); if (provider != null) { IEnumerable <SiteAlias> aliases = provider.Get(name); JArray jaliases = Jsonifier.ToJson(aliases); if (jaliases != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jaliases.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } }
private static void GetChildren(CompoundIdentity cid, UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { SiteProviderBase provider = SiteManager.Instance.GetSiteProvider(user); if (provider != null) { IEnumerable <Site> sites = provider.GetChildren(cid); JArray jchildren = Jsonifier.ToJson(sites); if (jchildren != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, jchildren.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } }
private static void GetIds(HashSet <CompoundIdentity> idList, UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { if (idList.Count == 0) { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); return; } SiteAliasSchemeProviderBase provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null) { JObject scheme = null; JArray schemes = new JArray(); foreach (CompoundIdentity cid in idList) { scheme = Jsonifier.ToJson(provider.Get(cid)); if (scheme != null) { schemes.Add(scheme); } } if (schemes != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, schemes.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, JsonOpStatus.Failed); return; } }
private static void GetOrgAndName(CompoundIdentity orgid, String name, UserSecurityContext user, HttpContext context, CancellationToken cancel) { try { SiteAliasSchemeProviderBase provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null) { JArray schemes = null; if (orgid != null && !string.IsNullOrEmpty(name)) { schemes = Jsonifier.ToJson(provider.GetByOwner(orgid, name)); } else if (orgid != null) { schemes = Jsonifier.ToJson(provider.GetByOwner(orgid)); } else if (!string.IsNullOrEmpty(name)) { schemes = Jsonifier.ToJson(provider.Get(name)); } if (schemes != null) { RestUtils.Push(context.Response, JsonOpStatus.Ok, schemes.ToString()); } else { RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]"); } return; } RestUtils.Push(context.Response, JsonOpStatus.Failed); } catch { RestUtils.Push(context.Response, JsonOpStatus.Failed); } }
// ---> /sites/schemes/all public static void Handle(UserSecurityContext user, string method, HttpContext context, CancellationToken cancel) { if (context.Request.Method == "POST") { if (method.Equals("all", StringComparison.OrdinalIgnoreCase)) { Get(user, context, cancel); return; } else if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); if (token != null) { string name = null; CompoundIdentity org_id = null; if (token["name"] != null) { name = token["name"].ToString(); } if (token["orgid"] != null) { org_id = JsonUtils.ToId(token["orgid"]); } GetOrgAndName(org_id, name, 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("in", StringComparison.OrdinalIgnoreCase)) { try { HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request)); if (ids != null) { GetIds(ids, 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("create", StringComparison.OrdinalIgnoreCase)) { CompoundIdentity orgid = null; string name = null; string desc = null; JToken token = null; SiteAliasSchemeProviderBase provider = null; try { //payload and provider token = JsonUtils.GetDataPayload(context.Request); provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null && token != null) { //required inputs name = token["name"].ToString(); orgid = JsonUtils.ToId(token["orgid"]); if (!string.IsNullOrEmpty(name) && orgid != null) { //optionals desc = token["desc"] != null ? token["desc"].ToString() : null; //create SiteAliasScheme scheme = scheme = provider.Create(orgid, name, desc); if (scheme != null) { JObject jscheme = Jsonifier.ToJson(scheme); if (jscheme != null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jscheme.ToString())); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase)) { try { JToken t = JsonUtils.GetDataPayload(context.Request); CompoundIdentity cid = JsonUtils.ToId(t); SiteAliasSchemeProviderBase provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null && cid != null) { bool result = provider.Delete(cid); if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("update", StringComparison.OrdinalIgnoreCase)) { CompoundIdentity cid = null; CompoundIdentity org_cid = null; string name = null; string desc = null; try { //provider and token JToken token = JsonUtils.GetDataPayload(context.Request); SiteAliasSchemeProviderBase provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (provider != null && token != null) { //GUID must be provided cid = JsonUtils.ToId(token["id"]); //fetch stored object bool dirty = false; SiteAliasScheme scheme = provider.Get(cid); if (scheme == null) { //## REQUIRED ## //name if (token.SelectToken("name") != null) { name = token["name"].ToString(); if (!string.IsNullOrEmpty(name)) { scheme.Name = name; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable return; } } //owning org if (token.SelectToken("orgid") != null) { org_cid = JsonUtils.ToId(token["orgid"]); if (org_cid != null) { scheme.OwningOrganizationIdentity = org_cid; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable return; } } //## OPTIONALS ## //description if (token.SelectToken("desc") != null) { desc = (token["desc"] != null) ? token["desc"].ToString() : null; scheme.Description = desc; dirty = true; } if (dirty) { //update bool result = provider.Update(scheme); if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } else { //return ok - no values were modified RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(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("all", StringComparison.OrdinalIgnoreCase)) { Get(user, context, cancel); return; } else if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); if (token != null) { if (token["id"] != null && token["schemeid"] != null) { GetBySiteAndScheme(JsonUtils.ToId(token["id"]), JsonUtils.ToId(token["schemeid"]), user, context, cancel); return; } else if (token["id"] != null && token["name"] != null) { GetBySiteAndName(JsonUtils.ToId(token["id"]), token["name"].ToString(), user, context, cancel); return; } else if (token["schemeid"] != null && token["name"] != null) { GetBySchemeAndName(JsonUtils.ToId(token["schemeid"]), token["name"].ToString(), user, context, cancel); return; } else if (token["schemeid"] != null) { GetByScheme(JsonUtils.ToId(token["schemeid"]), user, context, cancel); return; } else if (token["id"] != null) { GetBySite(JsonUtils.ToId(token["id"]), user, context, cancel); return; } else if (token["name"] != null) { GetByName(token["name"].ToString(), 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("create", StringComparison.OrdinalIgnoreCase)) { try { //token and providers JToken token = JsonUtils.GetDataPayload(context.Request); SiteAliasProviderBase alias_provider = SiteManager.Instance.GetSiteAliasProvider(user); SiteProviderBase site_provider = SiteManager.Instance.GetSiteProvider(user); SiteAliasSchemeProviderBase scheme_provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (alias_provider != null && scheme_provider != null && site_provider != null && token != null) { //required string name = token["name"].ToString(); SiteAliasScheme scheme = scheme_provider.Get(JsonUtils.ToId(token["schemeid"])); Site site = site_provider.Get(JsonUtils.ToId(token["id"])); if (site != null && scheme != null && !string.IsNullOrEmpty(name)) { //create object SiteAlias alias = alias_provider.Create(scheme, site, name); if (alias != null) { JObject jalias = Jsonifier.ToJson(alias); if (jalias != null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jalias.ToString())); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("update", StringComparison.OrdinalIgnoreCase)) { try { //token and providers JToken token = JsonUtils.GetDataPayload(context.Request); SiteAliasProviderBase alias_provider = SiteManager.Instance.GetSiteAliasProvider(user); SiteProviderBase site_provider = SiteManager.Instance.GetSiteProvider(user); SiteAliasSchemeProviderBase scheme_provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (alias_provider != null && scheme_provider != null && site_provider != null && token != null) { //required fields CompoundIdentity site_id = JsonUtils.ToId(token["id"]); Site site = site_provider.Get(site_id); CompoundIdentity scheme_id = JsonUtils.ToId(token["schemeid"]); SiteAliasScheme scheme = scheme_provider.Get(scheme_id); string old_name = token["name"].ToString(); string new_name = token["newname"].ToString(); if (site != null && scheme == null && !string.IsNullOrEmpty(old_name) && !string.IsNullOrEmpty(new_name)) { //retrieve by site, scheme IEnumerable <SiteAlias> aliases = alias_provider.Get(site_id, scheme); if (aliases == null) { //match alias by name (an org could have multiple aliases in the same scheme, but they must be unique) SiteAlias alias = null; foreach (SiteAlias a in aliases) { if (a.Name == old_name) { alias = a; } } alias.Name = new_name; bool result = alias_provider.Update(alias); if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase)) { CompoundIdentity scheme_id = null; CompoundIdentity site_id = null; SiteAliasScheme scheme = null; Site site = null; string name = null; try { //token and providers JToken token = JsonUtils.GetDataPayload(context.Request); SiteAliasProviderBase alias_provider = SiteManager.Instance.GetSiteAliasProvider(user); SiteProviderBase site_provider = SiteManager.Instance.GetSiteProvider(user); SiteAliasSchemeProviderBase scheme_provider = SiteManager.Instance.GetSiteAliasSchemeProvider(user); if (alias_provider != null && scheme_provider != null && site_provider != null && token != null) { //If a token is provided, it cannot be null //Checking values against intent avoids firing a degenerate delete override //schemeid if (token.SelectToken("schemeid") != null) { if (token["schemeid"] == null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } else { scheme_id = JsonUtils.ToId(token["schemeid"]); scheme = scheme_provider.Get(scheme_id); } } //id if (token.SelectToken("id") != null) { if (token["id"] == null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } else { site_id = JsonUtils.ToId(token["id"]); site = site_provider.Get(site_id); } } //name if (token.SelectToken("name") != null) { if (token["name"] == null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } else { name = token["name"].ToString(); } } //determine override bool result = false; if (scheme != null && site != null && name != null) //delete specific alias { //don't have a provider method that returns specific alias, so get by site, scheme and match alias by name (most of the time a single alias will be returned) IEnumerable <SiteAlias> aliases = alias_provider.Get(site_id, scheme); if (aliases != null) { foreach (SiteAlias alias in aliases) { if (alias.Name == name) { result = alias_provider.Delete(alias); break; //aliases should be unique for a given site in a given scheme } } } } else if (scheme != null && site_id != null) { result = alias_provider.Delete(site_id, scheme); //delete * for given site in a given scheme (could be multiple) } else if (scheme != null) { result = alias_provider.Delete(scheme); //delete * for a given scheme (across orgs) } else if (site_id != null) { result = alias_provider.Delete(site_id); //delete * for a given org (across schemes) } if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(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("all", StringComparison.OrdinalIgnoreCase)) { Get(user, context, cancel); return; } else if (method.Equals("find", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); if (token != null) { if (token["name"] != null) { GetName(token["name"].ToString(), user, context, cancel); return; } else if (token["orgid"] != null) { GetByOwner(JsonUtils.ToId(token["orgid"]), 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("in", StringComparison.OrdinalIgnoreCase)) { try { HashSet <CompoundIdentity> ids = JsonUtils.ToIds(JsonUtils.GetDataPayload(context.Request)); if (ids != null) { GetIds(ids, 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("parent", StringComparison.OrdinalIgnoreCase)) { try { JToken token = JsonUtils.GetDataPayload(context.Request); CompoundIdentity id = JsonUtils.ToId(token["id"]); CompoundIdentity parentid = JsonUtils.ToId(token["parentid"]); HashSet <CompoundIdentity> cids = JsonUtils.ToIds(token["childid"]); bool del = token["remove"] != null ? (bool)token["remove"] : false; if (parentid != null && cids != null) { if (del) { Remove(parentid, cids, user, context, cancel); return; } else { Add(parentid, cids, user, context, cancel); return; } } else if (id != null) { GetParent(id, 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("children", StringComparison.OrdinalIgnoreCase)) { try { CompoundIdentity cid = JsonUtils.ToId(JsonUtils.GetDataPayload(context.Request)); if (cid != null) { GetChildren(cid, 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("create", StringComparison.OrdinalIgnoreCase)) { CompoundIdentity owning_orgid = null; string name = null; string desc = null; SiteProviderBase provider = null; JToken token = null; try { //payload and provider token = JsonUtils.GetDataPayload(context.Request); provider = SiteManager.Instance.GetSiteProvider(user); if (provider != null && token != null) { //required inputs name = token["name"].ToString(); owning_orgid = JsonUtils.ToId(token["orgid"]); if (owning_orgid != null && !string.IsNullOrEmpty(name)) { desc = token["desc"] != null ? token["desc"].ToString() : null; HashSet <CompoundIdentity> pids = JsonUtils.ToIds(token["parentid"]); //could be >= 1, or null //create Site site = null; site = provider.Create(owning_orgid, name, desc); if (site != null) { //add parents if necessary bool result = true; if (pids != null) { foreach (CompoundIdentity p in pids) { result &= provider.AddParent(site.Identity, p); //parents are not returned with newly created site. This was just a convenience for REST /create } } if (result == true) { JObject jsite = Jsonifier.ToJson(site); if (jsite != null) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jsite.ToString())); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("delete", StringComparison.OrdinalIgnoreCase)) { try { JToken t = JsonUtils.GetDataPayload(context.Request); HashSet <CompoundIdentity> cids = JsonUtils.ToIds(t); SiteProviderBase provider = SiteManager.Instance.GetSiteProvider(user); if (provider != null && cids != null) { bool result = true; foreach (CompoundIdentity cid in cids) { result &= provider.Delete(cid); } if (result == true) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } return; } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } else if (method.Equals("update", StringComparison.OrdinalIgnoreCase)) { CompoundIdentity cid = null; CompoundIdentity org_cid = null; HashSet <CompoundIdentity> pids = null; string name = null; string desc = null; bool dirty = false; try { //provider and token JToken token = JsonUtils.GetDataPayload(context.Request); SiteProviderBase provider = SiteManager.Instance.GetSiteProvider(user); if (provider != null && token != null) { //GUID must be provided cid = JsonUtils.ToId(token["id"]); //fetch stored object Site site = provider.Get(cid); if (site != null) { //## REQUIRED ## //name if (token.SelectToken("name") != null) { name = token["name"].ToString(); if (!string.IsNullOrEmpty(name)) { site.Name = name; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //name is required and not nullable return; } } //owning org if (token.SelectToken("orgid") != null) { org_cid = JsonUtils.ToId(token["orgid"]); if (org_cid != null) { site.OwningOrganizationIdentity = org_cid; dirty = true; } else { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); //owning org is required and not nullable return; } } //## OPTIONALS ## //description if (token.SelectToken("desc") != null) { desc = (token["desc"] != null) ? token["desc"].ToString() : null; site.Description = desc; dirty = true; } //geom if (token.SelectToken("geom") != null) { IGeometry2 <double> geom = Jsonifier.IsNullOrEmpty(token["geom"]) ? null : GeoJsonUtils.ParseGeometry(token["geom"].ToString()); site.Location = geom; dirty = true; } //altgeom if (token.SelectToken("altgeom") != null) { Point2 <double> altgeom = Jsonifier.IsNullOrEmpty(token["altgeom"]) ? null : GeoJsonUtils.ParseGeometry(token["altgeom"].ToString()) as Point2 <double>; site.LocationMark = altgeom; dirty = true; } //update bool result = true; if (dirty) { //update result &= provider.Update(site); if (result == false) { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } //site hierarchy if (token.SelectToken("parentid") != null) { pids = JsonUtils.ToIds(token["parentid"]); //new parents IEnumerable <Site> existing_parents = provider.GetParents(cid); //existing parents if (pids == null) //clear all parent assignments { foreach (Site p in existing_parents) { result &= provider.RemoveParent(cid, p.Identity); } } else { //remove unlisted, keep listed foreach (Site p in existing_parents) { if (pids.Contains(p.Identity) == false) { result &= provider.RemoveParent(cid, p.Identity); } } //add new foreach (CompoundIdentity new_pid in pids) { bool contains = false; foreach (Site p in existing_parents) { if (p.Identity == new_pid) { contains = true; } break; } if (contains == false) { result &= provider.AddParent(cid, new_pid); } } } } if (result == true) { //return ok - no values were modified RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok)); return; } } } RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); } catch { RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed)); return; } } } context.Response.StatusCode = HttpStatusCodes.Status400BadRequest; }