Esempio n. 1
0
        public IEnumerable <ScriptedPatchCommandData> Establish(UserProfile user, ManagerOf managerOf,
                                                                OrganizationProfile organization, HasManager hasManager)
        {
            const string patchScript = "var _this = this;" +
                                       "function addRelation(clrType, relation, thisArg) {" +
                                       "   (thisArg || _this).Relations.push(_.extend({ '$type': clrType }, relation));" +
                                       "}" + "addRelation(relationClrType, relation);";

            yield return(new ScriptedPatchCommandData
            {
                Key = user.Id,
                Patch = new ScriptedPatchRequest
                {
                    Script = patchScript,
                    Values = new Dictionary <string, object>
                    {
                        { "relation", managerOf },
                        { "relationClrType", ClrType(managerOf.GetType()) }
                    }
                }
            });

            yield return(new ScriptedPatchCommandData
            {
                Key = organization.Id,
                Patch = new ScriptedPatchRequest
                {
                    Script = patchScript,
                    Values = new Dictionary <string, object>
                    {
                        { "relation", hasManager },
                        { "relationClrType", ClrType(hasManager.GetType()) }
                    }
                }
            });
        }
Esempio n. 2
0
        private IEnumerable <PatchCommandData> Establish(UserProfile user, ManagerOf managerOf,
                                                         OrganizationProfile organization, HasManager hasManager)
        {
            const string patchScript = "var _this = this;" +
                                       "function addRelation(clrType, relation, thisArg) {" +
                                       " relation['$type'] = clrType; " +
                                       "   (thisArg || _this).Relations.push(relation);" +
                                       "}" + "addRelation(args.relationClrType, args.relation);";

            yield return(new PatchCommandData(user.Id, null, new PatchRequest
            {
                Script = patchScript,
                Values = new Dictionary <string, object>
                {
                    { "relation", managerOf },
                    { "relationClrType", ClrType(managerOf.GetType()) }
                }
            }, null));

            yield return(new PatchCommandData(organization.Id, null, new PatchRequest
            {
                Script = patchScript,
                Values = new Dictionary <string, object>
                {
                    { "relation", hasManager },
                    { "relationClrType", ClrType(hasManager.GetType()) }
                }
            }, null));
        }