Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
get Region filled (url parameter): http://host:port/regions?type=filled

Method GET

Response 200 as array (application/json):

[{regionobject},{…}…]
regionobject structure:
{region_id : value,
region_name : value,
region_fullname : value,
region_type : valuee
region_misc : value,
projects: [{projectobject},{…}…]}

projectobject structure:
{project_id : value,
project_name : value,
project_code : value,
project_description : value,
region_id : value, (to avoid redundancy)
epsg : value,
sections : [{sectionobject},{…}…]}

sectionobject structure:
{section_id : value,
section_name : value,
section_description : value,
flights: [{flightobject},{…}…]}

flightobject structure:
{flight_id : value,
flight_misc : value,
flight_time : value,
user_id : value,
section_id : value,
flight_pictures_quantity : value,
flight_zip_filesize_mb : value,
processes : [{processobject},{…}…],
services : [{serviceobject},{…}…]}

What I have tried:

I tried using the data, but unfortunately it doesn't work for me. now i am completely blank.any guide on this will be appreciated.
Posted
Updated 26-Apr-20 22:50pm

Well, if I'm working on a REST API and I have control, I usually model the Data as C# POCO classes, and have a 'root' class containing the data hierarchy.

Then I usually serialize the C# classes from the 'root' class to JSON. That means I can handle complexity IF I need to - I avoid recursion for example, flattening out data as much as I can

If I'm going the other way, ie consuming someone else's JSON, I usually use json2csharp, feed in the json and get a C# structure built for me, which pretty well gives me a 'root' class to start with.

(and sometimes I do both ways to cross-check and make sure what I have is useable)

json2csharp seems to be down at the moment, the domain name has expired ?, but its a useful site

In your case in your controller, and depending on where your data comes from, I would have maybe

class RegionObject 
{
	string region_id {get; set;}
	region_name {get; set;}
	region_fullname {get; set;}
	region_type {get; set;}
	region_misc {get; set;}
	// List<Project> projects {get; set;}
}

public class RootData
{
    public List<RegionObject> regions { get; set; }
    public ProjectObject project { get; set; }
...
}

RootData root = new RootData();

RegionObject region = new RegionObject();
region.region_id = "some value";
...
region.region_misc = "some value";

root.regions.Add(region);
// Add more regions

string output = JsonConvert.SerializeObject(root);



Does that help ?
 
Share this answer
 
v5
Comments
Member 14153700 26-Apr-20 23:44pm    
@Garth J Lancaster. Can i get the solution. i tried many things but it doesn't worked for me
Garth J Lancaster 27-Apr-20 0:09am    
I've expanded the example a little, but, you havnt shown any code of your own, nor indicated where your data comes from, so that's about all I can/am willing to do
Member 14153700 27-Apr-20 2:50am    
I am trying to analyze possible way to achieve like this. the values comes from data base tables.. architect is There are many regions and each regions has many
projects which in turn has many section in it [{region_id : value, region_name : value, region_fullname : value, region_type : value, region_misc : value, projects: [{project_id : value,
project_name : value,
project_code : value,
project_description : value,
region_id : value,
epsg : value,
sections : [{id:value},{name : value}],sections:[{id :value},{name:value}]
Garth J Lancaster 27-Apr-20 4:45am    
I have to say, looking at your data model, I'd be simplifying it for a REST point of view

[{regionobject},{…}…]
regionobject structure:
{region_id : value,
region_name : value,
region_fullname : value,
region_type : valuee
region_misc : value,
projects: [{projectobject},{…}…]}


Would be two data domains,

/api/regions
/api/projects

and then maybe an aggregator that returns a joined 'set'
Member 14153700 27-Apr-20 4:52am    
Below is the table structure and expected output @Garth J Lancaster
public partial class Regions
    {
        public Regions()
        {
            Projects = new HashSet<Projects>();
            RegionUserRelation = new HashSet<RegionUserRelation>();
        }

        public int RegionId { get; set; }
        [Required]
        public string RegionName { get; set; }
        [Required]
        public string RegionFullname { get; set; }
        [Required]
        public int RegionTypeId { get; set; }
        public string RegionMisc { get; set; }

        public RegionType RegionType { get; set; }
        public ICollection<Projects> Projects { get; set; }
        public ICollection<RegionUserRelation> RegionUserRelation { get; set; }
    }

public partial class Projects
    {
        public Projects()
        {
            Sections = new HashSet<Sections>();
        }

        public Guid ProjectId { get; set; }
        [Required]
        public string ProjectName { get; set; }
        [Required]
        public string ProjectCode { get; set; }
        public string ProjectDesc { get; set; }
        [Required]
        public int RegionId { get; set; }
        [Required]
        public int EpsgId { get; set; }

        public Epsg Epsg { get; set; }
        public Regions Region { get; set; }
        public ICollection<Sections> Sections { get; set; }
    }


public partial class Sections
    {
        public Sections()
        {
            Flights = new HashSet<Flights>();
        }

        public Guid SectionId { get; set; }
        [Required]
        public string SectionName { get; set; }
        public string SectionDesc { get; set; }
        [Required]
        public Guid ProjectId { get; set; }

        public Projects Project { get; set; }
        public ICollection<Flights> Flights { get; set; }
    }



Expected output

{ "Regions" : 
  [ { 
        "region_id" : "2012",
        "region_name" : "region1",
        "region_fullname" : "21700",
        "region_type" : "MERCH",
            "Projects" : [ 
               {     "project_id" : 2341,
                     "project_name " : "DXY",
                     "project_code " : "21700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            "Projects" : [ 
               {     "project_id" : 1321,
                     "project_name " : "Proj_2",
                     "project_code " : "01700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            ]
  },
  { 
        "region_id" : "2013",
        "region_name" : "region3",
        "region_fullname" : "21330",
        "region_type" : "MERCH",
            "Projects" : [ 
               {     "project_id" : 2341,
                     "project_name " : "DXY",
                     "project_code " : "21700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            "Projects" : [ 
               {     "project_id" : 1321,
                     "project_name " : "Proj_2",
                     "project_code " : "01700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            ]
  },
  { 
        "region_id" : "2012",
        "region_name" : "region2",
        "region_fullname" : "24300",
        "region_type" : "MERCH",
            "Projects" : [ 
               {     "project_id" : 2341,
                     "project_name " : "DXY",
                     "project_code " : "21700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            "Projects" : [ 
               {     "project_id" : 1321,
                     "project_name " : "Proj_2",
                     "project_code " : "01700",
                     "sections" : [
                                { "section_id" : 4356,
                                "section_name" : sec_name,
                                "section_description" : sec_dis},
                                { "section_id" : 476,
                                "section_name" : sec_name2,
                                "section_description" : sec_dis2},
                                { "section_id" : 908,
                                "section_name" : sec_name3,
                                "section_description" : sec_dis3}
                            ]
                },
            ]
  },
] }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900