Example #1
0
        /// <summary>
        /// Pushes the type to json.
        /// </summary>
        /// <param name="audience">The audience.</param>
        /// <returns>System.Object.</returns>
        public static JProperty ToJson(this Audience audience)
        {
            const string propertyName = "audience";

            if (audience != null)
            {
                if (audience.ContainsKey(PushTypeV3.Broadcast))
                {
                    return(new JProperty(propertyName, "all"));
                }
                else
                {
                    JObject obj = new JObject();

                    foreach (var one in audience.Keys)
                    {
                        switch (one)
                        {
                        case PushTypeV3.ByAlias:
                            obj.Add(new JProperty("alias", audience[one]));
                            break;

                        case PushTypeV3.ByRegistrationId:
                            obj.Add(new JProperty("registration_id", audience[one]));
                            break;

                        case PushTypeV3.ByTagWithinAnd:
                            obj.Add(new JProperty("tag_and", audience[one]));
                            break;

                        case PushTypeV3.ByTagWithinOr:
                            obj.Add(new JProperty("tag", audience[one]));
                            break;

                        default:
                            break;
                        }
                    }

                    return(new JProperty(propertyName, obj));
                }
            }

            return(null);
        }