Beispiel #1
0
        public async Task <IHttpActionResult> PostAssignChild(string id, newChildInfo info)
        {
            var g = new GremlinHelper();

            if (info == null || string.IsNullOrWhiteSpace(info.id) || (string.IsNullOrWhiteSpace(info.motherId) && string.IsNullOrWhiteSpace(info.fatherId)))
            {
                return(BadRequest());
            }

            var ncID = info.id;

            // relate to parent
            await g.getResultAsync($"g.V('{id}').addE('parent').to(g.V('{ncID}'))");

            // now other parent
            if (!string.IsNullOrWhiteSpace(info.motherId) && info.motherId != id)
            {
                await g.getResultAsync($"g.V('{info.motherId}').addE('parent').to(g.V('{ncID}'))");
            }
            else if (!string.IsNullOrWhiteSpace(info.fatherId) && info.fatherId != id)
            {
                await g.getResultAsync($"g.V('{info.fatherId}').addE('parent').to(g.V('{ncID}'))");
            }

            // add parent Edge type properties
            if (!string.IsNullOrWhiteSpace(info.fatherId))
            {
                await g.getResultAsync($"g.V('{info.fatherId}').outE('parent').property('type', 'Father')");
            }
            if (!string.IsNullOrWhiteSpace(info.motherId))
            {
                await g.getResultAsync($"g.V('{info.motherId}').outE('parent').property('type', 'Mother')");
            }

            // save age on Edge
            if (!string.IsNullOrWhiteSpace(info.fatherAge))
            {
                await g.getResultAsync($"g.V('{info.fatherId}').outE('parent').inV('{ncID}').property('age', '{info.fatherAge}')");
            }
            if (!string.IsNullOrWhiteSpace(info.motherAge))
            {
                await g.getResultAsync($"g.V('{info.motherId}').outE('parent').inV('{ncID}').property('age', '{info.motherAge}')");
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PostNewChild(string id, newChildInfo info)
        {
            var g = new GremlinHelper();

            if (info == null)
            {
                return(BadRequest());
            }

            string ncID;

            if (!string.IsNullOrWhiteSpace(info.name) && info.id == null)
            {
                // do the insert
                var qry = $"g.addV('person').property('name', '{info.name}')";
                if (!string.IsNullOrWhiteSpace(info.gender))
                {
                    qry += $".property('gender', '{info.gender}')";
                }
                var nc = await g.getResultAsync(qry);

                // get iD frmo result
                ncID = (nc as JObject)["id"].ToString();
            }
            else
            {
                ncID = info.id;
            }

            // relate to parent
            await g.getResultAsync($"g.V('{id}').addE('parent').to(g.V('{ncID}'))");

            // now other parent
            if (!string.IsNullOrWhiteSpace(info.motherId) && info.motherId != id)
            {
                await g.getResultAsync($"g.V('{info.motherId}').addE('parent').to(g.V('{ncID}'))");
            }
            else if (!string.IsNullOrWhiteSpace(info.fatherId) && info.fatherId != id)
            {
                await g.getResultAsync($"g.V('{info.fatherId}').addE('parent').to(g.V('{ncID}'))");
            }

            // add parent Edge type properties
            if (!string.IsNullOrWhiteSpace(info.fatherId))
            {
                await g.getResultAsync($"g.V('{info.fatherId}').outE('parent').property('type', 'Father')");
            }
            if (!string.IsNullOrWhiteSpace(info.motherId))
            {
                await g.getResultAsync($"g.V('{info.motherId}').outE('parent').property('type', 'Mother')");
            }

            // save age on Edge
            if (!string.IsNullOrWhiteSpace(info.fatherAge))
            {
                await g.getResultAsync($"g.V('{ncID}').inE('parent').has('type', 'Father').property('age', '{info.fatherAge}')");
            }
            if (!string.IsNullOrWhiteSpace(info.motherAge))
            {
                await g.getResultAsync($"g.V('{ncID}').inE('parent').has('type', 'Mother').property('age', '{info.motherAge}')");
            }

            return(Ok());
        }