public static JsonValue AddUser(Cache cache, string email, string firstName, string lastName)
 {
     email = email.ToLower();
     var ret = new JsonObject();
     if (EmailExists(cache, email))
     {
         ret["email"] = email;
         ret["message"] = "Email already exists";
     }
     else
     {
         var cacheItm = new Tuple<string, string>(firstName, lastName);
         cache.Add(email, cacheItm, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0), CacheItemPriority.Normal, null);
         ret.AsDynamic().email = email;
         ret.AsDynamic().firstName = cacheItm.Item1;
         ret.AsDynamic().lastName = cacheItm.Item2;
         ret.AsDynamic().message = "Added";
     }
     return ret;
 }
Exemple #2
0
        public void DynamicEventsTest()
        {
            int       seed   = 1;
            int       maxObj = 10;
            JsonArray ja     = new JsonArray();
            dynamic   d      = ja.AsDynamic();

            TestEventsDynamic(
                d,
                (Action <dynamic>)(arr => arr.Add(1)),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, ja, new JsonValueChangeEventArgs(1, JsonValueChange.Add, 0)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, ja, new JsonValueChangeEventArgs(1, JsonValueChange.Add, 0)),
            });

            const string key1 = "first";
            const string key2 = "second";
            JsonObject   jo   = new JsonObject
            {
                { key1, SpecialJsonValueHelper.GetRandomJsonPrimitives(seed) },
            };

            JsonObject objectToAdd = SpecialJsonValueHelper.CreateRandomPopulatedJsonObject(seed, maxObj);
            dynamic    d2          = jo.AsDynamic();

            TestEventsDynamic(
                d2,
                (Action <dynamic>)(obj => obj[key2] = objectToAdd),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Add, key2)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Add, key2)),
            });

            TestEventsDynamic(
                d2,
                (Action <dynamic>)(obj => obj[key2] = objectToAdd),
                new List <Tuple <bool, JsonValue, JsonValueChangeEventArgs> >
            {
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(true, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Replace, key2)),
                new Tuple <bool, JsonValue, JsonValueChangeEventArgs>(false, jo, new JsonValueChangeEventArgs(objectToAdd, JsonValueChange.Replace, key2)),
            });
        }