Beispiel #1
0
        private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                if (provider != null)
                {
                    IEnumerable <OrganizationAliasScheme> 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, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Beispiel #2
0
        private static void GetByOrg(CompoundIdentity org_id, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasProvider(user);
                Organization org = OrganizationManager.Instance.GetOrganizationProvider(user).Get(org_id);
                if (org != null && provider != null)
                {
                    IEnumerable <OrganizationAlias> aliases = provider.Get(org);
                    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));
            }
        }
Beispiel #3
0
        private static void GetOrgAndName(CompoundIdentity orgid, string name, UserSecurityContext user, HttpContext context, CancellationToken cancel)
        {
            try
            {
                OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                Organization org = OrganizationManager.Instance.GetOrganizationProvider(user).Get(orgid);
                if (org != null && provider != null)
                {
                    IEnumerable <OrganizationAliasScheme> schemes = provider.Get(org, name);
                    JArray jschemes = Jsonifier.ToJson(schemes);
                    if (jschemes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jschemes.ToString());
                    }
                    else
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
                    }
                }

                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
            catch
            {
                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
            }
        }
Beispiel #4
0
 private static void Get(UserSecurityContext user, HttpContext context, CancellationToken cancel)
 {
     try
     {
         OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
         OrganizationHierarchy             hierarchy = provider.GetReporting();
         if (provider != null)
         {
             IEnumerable <KeyValuePair <CompoundIdentity, CompoundIdentity> > links = hierarchy.GetAllPairs();
             JArray jlinks = Jsonifier.ToJson(links);
             if (jlinks != null)
             {
                 RestUtils.Push(context.Response, JsonOpStatus.Ok, jlinks.ToString());
             }
             else
             {
                 RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");
             }
         }
         RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
     }
     catch
     {
         RestUtils.Push(context.Response, JsonOpStatus.Failed);
         return;
     }
 }
Beispiel #5
0
 private static void GetParent(CompoundIdentity cid, UserSecurityContext user, HttpContext context, CancellationToken cancel)
 {
     try
     {
         OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
         OrganizationHierarchy             hierarchy = provider.GetReporting();
         if (provider != null)
         {
             IEnumerable <CompoundIdentity> parentids = hierarchy.GetParentIds(cid);
             JArray jparentids = Jsonifier.ToJson(parentids);
             if (jparentids != null)
             {
                 RestUtils.Push(context.Response, JsonOpStatus.Ok, jparentids.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));
         return;
     }
 }
Beispiel #6
0
        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;
                }

                OrganizationProviderBase provider = OrganizationManager.Instance.GetOrganizationProvider(user);
                if (provider != null)
                {
                    IEnumerable <Organization> orgs = provider.Get(idList);
                    JArray jorgs = Jsonifier.ToJson(orgs);
                    if (jorgs != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jorgs.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));
                return;
            }
        }
Beispiel #7
0
        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;
                }

                OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                if (provider != null)
                {
                    JObject jscheme  = null;
                    JArray  jschemes = new JArray();
                    foreach (CompoundIdentity cid in idList)
                    {
                        jscheme = Jsonifier.ToJson(provider.Get(cid));
                        jschemes.Add(jscheme);
                    }

                    if (jschemes != null)
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Ok, jschemes.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));
            }
        }
Beispiel #8
0
        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["orgid"] != null && token["name"] != null)
                        {
                            GetOrgAndName(JsonUtils.ToId(token["orgid"]), token["name"].ToString(), user, context, cancel);
                            return;
                        }
                        else if (token["name"] != null)
                        {
                            GetName(token["name"].ToString(), user, context, cancel);
                            return;
                        }
                        else if (token["orgid"] != null)
                        {
                            CompoundIdentity cid = JsonUtils.ToId(token["orgid"]);
                            GetOrg(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("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));
                    }
                }
                else if (method.Equals("create", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        string name = null;
                        string desc = null;

                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        name = token["name"].ToString();
                        OrganizationProviderBase            o        = OrganizationManager.Instance.GetOrganizationProvider(user);
                        OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        if (provider != null && o != null && token != null && !string.IsNullOrEmpty(name))
                        {
                            CompoundIdentity        orgid  = JsonUtils.ToId(token["orgid"]);
                            Organization            org    = o.Get(orgid);
                            OrganizationAliasScheme scheme = null;
                            desc = (token["desc"]) != null ? token["desc"].ToString() : null;

                            //create
                            scheme = provider.Create(org, name, desc);

                            if (scheme != null)
                            {
                                JObject jscheme = Jsonifier.ToJson(scheme);
                                RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jscheme.ToString()));
                                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);
                        OrganizationAliasSchemeProviderBase provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(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));
                                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))
                {
                    JToken           token = null;
                    CompoundIdentity cid   = null;
                    CompoundIdentity orgid = null;
                    OrganizationAliasSchemeProviderBase provider = null;
                    OrganizationAliasScheme             scheme   = null;
                    string name = null;
                    string desc = null;

                    try
                    {
                        //check for request.body and provider
                        token    = JsonUtils.GetDataPayload(context.Request);
                        provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        if (provider != null && token != null)
                        {
                            //GUID must be provided
                            cid = JsonUtils.ToId(token["id"]);

                            //fetch stored object
                            bool dirty = false;
                            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)
                                {
                                    orgid = JsonUtils.ToId(token["orgid"]);
                                    if (orgid != null)
                                    {
                                        scheme.OwningOrganizationIdentity = orgid;
                                        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;
        }
Beispiel #9
0
        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)
                            {
                                GetByOrgAndScheme(JsonUtils.ToId(token["id"]), JsonUtils.ToId(token["schemeid"]), user, context, cancel);
                                return;
                            }
                            else if (token["id"] != null && token["name"] != null)
                            {
                                GetByOrgAndName(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)
                            {
                                CompoundIdentity cid = JsonUtils.ToId(token["id"]);
                                GetByOrg(cid, 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);
                        OrganizationProviderBase            org_provider    = OrganizationManager.Instance.GetOrganizationProvider(user);
                        OrganizationAliasSchemeProviderBase scheme_provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        OrganizationAliasProviderBase       alias_provider  = OrganizationManager.Instance.GetOrganizationAliasProvider(user);
                        if (org_provider != null && scheme_provider != null && alias_provider != null && token != null)
                        {
                            //get inputs
                            OrganizationAliasScheme scheme = scheme_provider.Get(JsonUtils.ToId(token["schemeid"]));
                            Organization            org    = org_provider.Get(JsonUtils.ToId(token["id"]));
                            string name = token["name"].ToString();
                            if (scheme != null && org != null && !string.IsNullOrEmpty(name))
                            {
                                //create object
                                OrganizationAlias alias = alias_provider.Create(scheme, org, name);
                                if (alias != null)
                                {
                                    JObject jalias = Jsonifier.ToJson(alias);
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Ok, jalias.ToString()));
                                    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);
                        OrganizationAliasSchemeProviderBase scheme_provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        OrganizationAliasProviderBase       alias_provider  = OrganizationManager.Instance.GetOrganizationAliasProvider(user);
                        if (scheme_provider != null && alias_provider != null && token != null)
                        {
                            //required fields
                            CompoundIdentity        orgid  = JsonUtils.ToId(token["id"]);
                            OrganizationAliasScheme scheme = scheme_provider.Get(JsonUtils.ToId(token["schemeid"]));
                            string old_name = token["name"].ToString();
                            string new_name = token["newname"].ToString();
                            if (orgid != null && scheme != null && !string.IsNullOrEmpty(old_name) && !string.IsNullOrEmpty(new_name))
                            {
                                //get entity and modify its properties
                                IEnumerable <OrganizationAlias> aliases = alias_provider.Get(orgid, scheme);
                                if (aliases != null)
                                {
                                    //match alias by name (an org could have multiple aliases in the same scheme, but they must be unique)
                                    OrganizationAlias alias = null;
                                    foreach (OrganizationAlias 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        org_id    = null;
                    OrganizationAliasScheme scheme    = null;
                    string name = null;

                    try
                    {
                        JToken token = JsonUtils.GetDataPayload(context.Request);
                        OrganizationProviderBase            org_provider    = OrganizationManager.Instance.GetOrganizationProvider(user);
                        OrganizationAliasSchemeProviderBase scheme_provider = OrganizationManager.Instance.GetOrganizationAliasSchemeProvider(user);
                        OrganizationAliasProviderBase       provider        = OrganizationManager.Instance.GetOrganizationAliasProvider(user);
                        if (provider != null && scheme_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);
                                }
                            }

                            //orgid
                            if (token.SelectToken("id") != null)
                            {
                                if (token["id"] == null)
                                {
                                    RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                                    return;
                                }
                                else
                                {
                                    org_id = JsonUtils.ToId(token["id"]);
                                    Organization org = org_provider.Get(org_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_id != null && org_id != null && name != null)    //delete specific alias
                            {
                                //don't have a provider method that returns specific alias, so get by org, scheme and match alias by name (most of the time a single alias will be returned)
                                IEnumerable <OrganizationAlias> aliases = provider.Get(org_id, scheme);
                                if (aliases != null)
                                {
                                    foreach (OrganizationAlias alias in aliases)
                                    {
                                        if (alias.Name == name)
                                        {
                                            result = provider.Delete(alias);
                                            break;                                          //aliases should be unique for a given org in a given scheme
                                        }
                                    }
                                }
                            }
                            else if (scheme_id != null && org_id != null)               //delete * for given org in a given scheme
                            {
                                result = provider.Delete(org_id, scheme_id);
                            }

                            else if (scheme_id != null)                                 //delete * for a given scheme
                            {
                                result = provider.Delete(scheme);
                            }

                            else if (org_id != null)                                    //delete * for a given org
                            {
                                result = provider.Delete(org_id);
                            }

                            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;
        }
Beispiel #10
0
        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("children", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        //parse request
                        JToken           token      = JsonUtils.GetDataPayload(context.Request);
                        CompoundIdentity cid        = JsonUtils.ToId(token["parentid"]);
                        string           outputType = (token["outputType"] != null) ? token["outputType"].ToString() : "";
                        string           recurse    = token["recurse"] != null ? token["recurse"].ToString() : null;

                        //get default hierarchy
                        OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
                        OrganizationHierarchy             hierarchy = provider.GetReporting();

                        //get children ids
                        IEnumerable <CompoundIdentity> children = null;
                        if (recurse != null)
                        {
                            children = hierarchy.GetChildrenIds(cid, Convert.ToBoolean(recurse));
                        }
                        else
                        {
                            children = hierarchy.GetChildrenIds(cid);
                        }

                        if (children == null)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok, "[]");  //empty
                            return;
                        }

                        //return children ids or objects
                        JArray jchildren = null;
                        if (outputType.Equals("values"))
                        {
                            OrganizationProviderBase orgProvider = OrganizationManager.Instance.GetOrganizationProvider(user);
                            List <Organization>      orgs        = new List <Organization>();
                            foreach (CompoundIdentity child in children)
                            {
                                orgs.Add(orgProvider.Get(child));
                            }
                            jchildren = Jsonifier.ToJson(orgs);
                        }
                        else
                        {
                            jchildren = Jsonifier.ToJson(children);
                        }

                        if (jchildren != null)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok, jchildren.ToString());
                        }
                        else
                        {
                            RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));  //empty returned above
                        }
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, RestUtils.JsonOpStatus(JsonOpStatus.Failed));
                    }
                    return;
                }
                else if (method.Equals("parent", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        CompoundIdentity cid = JsonUtils.ToId(JsonUtils.GetDataPayload(context.Request));
                        if (cid != null)
                        {
                            GetParent(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("add", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        //parse request
                        JToken                     token      = JsonUtils.GetDataPayload(context.Request);
                        CompoundIdentity           parent     = JsonUtils.ToId(token["parentid"]);
                        HashSet <CompoundIdentity> child_cids = JsonUtils.ToIds(token["childid"]);  //1 or more

                        //get default hierarchy
                        OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
                        OrganizationHierarchy             hierarchy = provider.GetReporting();

                        //insert
                        bool result = hierarchy.Add(parent, child_cids);
                        if (result == true)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok);
                        }
                        else
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Failed);
                        }
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Failed);
                    }
                    return;
                }
                else if (method.Equals("move", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        //parse request
                        JToken                     token   = JsonUtils.GetDataPayload(context.Request);
                        CompoundIdentity           old_cid = JsonUtils.ToId(token["parentid"]);
                        CompoundIdentity           new_cid = JsonUtils.ToId(token["newparentid"]);
                        HashSet <CompoundIdentity> cids    = JsonUtils.ToIds(token["childid"]);

                        //get default hierarchy
                        OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
                        OrganizationHierarchy             hierarchy = provider.GetReporting();

                        //move
                        bool result = hierarchy.Move(old_cid, new_cid, cids);
                        if (result == true)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok);
                        }
                        else
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Failed);
                        }
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Failed);
                    }

                    return;
                }
                else if (method.Equals("remove", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        //parse request
                        JToken                     token      = JsonUtils.GetDataPayload(context.Request);
                        CompoundIdentity           parent_cid = JsonUtils.ToId(token["parentid"]);
                        HashSet <CompoundIdentity> child_cids = JsonUtils.ToIds(token["childid"]);

                        //get default hierarchy
                        OrganizationHierarchyProviderBase provider  = OrganizationHierarchyManager.Instance.GetProvider(user);
                        OrganizationHierarchy             hierarchy = provider.GetReporting();

                        //remove membership
                        bool result = hierarchy.Remove(parent_cid, child_cids);
                        if (result == true)
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Ok);
                        }
                        else
                        {
                            RestUtils.Push(context.Response, JsonOpStatus.Failed);
                        }
                    }
                    catch
                    {
                        RestUtils.Push(context.Response, JsonOpStatus.Failed);
                    }
                    return;
                }
            }
            context.Response.StatusCode = HttpStatusCodes.Status400BadRequest;
        }