Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gayan Sanjaya 3 posts 73 karma points
    14 days ago
    Gayan Sanjaya
    0

    JSON API feed return content base on the language.

    HI Sir,

    I want to develop JSON APi feed return the content base on the language.

    EX: api feed

    /umbraco/surface/AdminHelper/GetCampaign?campaign=abc&lang=frFR /umbraco/surface/AdminHelper/GetCampaign?campaign=abc&lang=enUS /umbraco/surface/AdminHelper/GetCampaign?campaign=abc&lang=it_IT

    For that I created HttpGet call in by using Umbraco.Web.Mvc.SurfaceController controller as below.

    [HttpGet] public ActionResult GetCampaign(string campaign, string lang)

    When I get the children of the contents it returns only default lange (en_Us) so please help me to sort out the multi language JSON feed.


    Blockquote

    [HttpGet] public ActionResult GetCampaign(string campaign, string lang) { dynamic result = new ExpandoObject();

            if (campaign == null)
            {
                return Content("Please set campain name query string parameter ex: ?campaign=xxxx", "application/json");
            }
    
            IDictionary<string,string> gc= Umbraco.CultureDictionary.GetChildren("en_US");          
    
            // NOTE - this code will need to be adjusted if there is a different naming convention
            var currentNode = Umbraco.ContentAtRoot().Where(x => x.Name == "Home").FirstOrDefault();
            var children = currentNode.ChildrenForAllCultures;
            var getCampainInfo = children.Where(x => x.Name.ToLower().Trim() == campaign.ToLower().Trim()).FirstOrDefault();
    
            if (getCampainInfo != null)
            {
                var getCampainGeneralNode = GetNodeValues(getCampainInfo);
                ((IDictionary<string, object>)result)[getCampainInfo.Name] = getCampainGeneralNode;
                var getCampainChildNode = getCampainInfo.ChildrenForAllCultures;
    
                var curElem = ((IDictionary<string, object>)result)[getCampainInfo.Name];
    
                foreach (var child2 in getCampainChildNode)
                {
                    ((IDictionary<string, object>)result)[child2.Name] = GetNodeValues(child2);
    
                    // Children - LEVEL 2
                    var childLevel3 = child2.Children;
                    var curElem2 = ((IDictionary<string, object>)result)[child2.Name];
                    var curChildArray = NodeChildrenAsArray(curElem2);
    
                    foreach (var child3 in childLevel3)
                    {
                        var childContent = GetNodeValues(child3);
                        var childLevel4 = child3.ChildrenForAllCultures;
                        var curChildArray2 = new List<dynamic>();
    
                        if (((IDictionary<string, object>)curElem2).ContainsKey("children"))
                        {
                            curChildArray.Add(childContent);
    
                            // TODO - need to handle where child elements of child elements are added
                        }
                        else
                        {
                            ((IDictionary<string, object>)curElem2)[child3.Name] = childContent;
    
                            // Children - LEVEL 3
                            var curElem3 = ((IDictionary<string, object>)curElem2)[child3.Name];
                            curChildArray2 = NodeChildrenAsArray(curElem3);
    
                            foreach (var child4 in childLevel4)
                            {
                                var childContent2 = GetNodeValues(child4);
                                var childLevel5 = child4.Children;
                                var curChildArray3 = new List<dynamic>();
    
                                if (((IDictionary<string, object>)curElem3).ContainsKey("children"))
                                {
                                    curChildArray2.Add(childContent2);
                                }
                                else
                                {
                                    ((IDictionary<string, object>)curElem3)[child4.Name] = childContent2;
    
                                    // Children - LEVEL 4
                                    var curElem4 = ((IDictionary<string, object>)child3)[child4.Name];
                                    curChildArray3 = this.NodeChildrenAsArray(curElem4);
                                }
                            }
                        }
                    }
                }
            }
    
            var json = JsonConvert.SerializeObject(result);
    
            return Content(json, "application/json");
        }
    

    Blockquote

    Please help me to sort this out.

    Thanks. :)

  • Gayan Sanjaya 3 posts 73 karma points
    1 week ago
    Gayan Sanjaya
    0

    any help

Please Sign in or register to post replies

Write your reply to:

Draft