Ejemplo n.º 1
0
        public override JToken Serialize(JaBuilderContext context)
        {
            JObject jb = new JObject();

            foreach (var property in GetType().GetProperties())
            {
                if (property.Name.Equals("name", StringComparison.CurrentCultureIgnoreCase))
                {
                    continue;
                }

                jb.Add(property.Name.ToLower(), context.GetPropertyValue(property.Name, this));
            }

            return(new JProperty(Name, jb));
        }
Ejemplo n.º 2
0
        public override JToken Serialize(JaBuilderContext context)
        {
            PreSetTemplate(context.ActionTemplate);

            JObject masterTemplate = GetTemplate(Constants.MASTER_TEMPLATE_NAME);

            List <string> propertiesNeedToRemove = new List <string>();

            foreach (var property in masterTemplate.Properties())
            {
                if (!hasError && property.Name.Equals("data"))
                {
                    property.Value = BuildResources(context);
                }
                else if (!hasError && property.Name.Equals("included"))
                {
                    property.Value = BuildResources(new JaBuilderContext(context.RequestMessage), context.IncludedResources, true);
                }
                else if (hasError && property.Name.Equals("errors"))
                {
                    property.Value = BuildResources(context);
                }
                else
                {
                    string key = property.EvaulationKey();

                    if (key == null)
                    {
                        continue;
                    }

                    property.Value = context.GetPropertyValue(key, this);
                }

                if (property.Value == null || property.Value.IsEmpty())
                {
                    propertiesNeedToRemove.Add(property.Name);
                }
            }

            propertiesNeedToRemove.ForEach(p => masterTemplate.Remove(p));

            return(masterTemplate);
        }
Ejemplo n.º 3
0
        public JToken Serialize(JaBuilderContext context)
        {
            foreach (var t in template.Properties())
            {
                if (t.Name.Equals("data"))
                {
                    t.Value = BuildData(context);
                }
                else
                {
                    string key = t.EvaulationKey();

                    if (key == null)
                    {
                        continue;
                    }

                    JToken jt = context.GetPropertyValue(key, GetPrimaryObject());
                    t.Value = jt ?? t.Value;
                }
            }

            return(template);
        }
Ejemplo n.º 4
0
        public virtual JToken BuildRelationships(JToken relationships, JaBuilderContext context)
        {
            JObject jObject = relationships as JObject; //relationships must be a object

            List <string> propertiesToRemove = new List <string>();

            foreach (var property in jObject.Properties())             //need to know what need to be built
            {
                JToken jt = context.GetPropertyValue(property.Name.Pascalize(), this, true);

                if (jt == null || jt.IsEmpty())
                {
                    propertiesToRemove.Add(property.Name);
                }
                else
                {
                    property.Value = jt;
                }
            }

            propertiesToRemove.ForEach(n => jObject.Remove(n));

            return(jObject);
        }