public bool ListThingsWithObs(string thingType, ref string errorMessage, ref List <IO.Swagger.Models.ThingsWithObservation> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var things = (from d in context.Thing
                                  join f in context.ThingTemplates
                                  on d.Templateid equals f.Thingtemplateid
                                  where f.Name == thingType
                                  select new
                                  { id = d.Thingid, name = d.Name, descripton = d.Description, status = d.Status, lat = d.Lat, lon = d.Lon, ThingTemplate = f.Name }
                                  ).ToList();

                    if (things == null)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var th in things)
                        {
                            IO.Swagger.Models.ThingsWithObservation z = new Models.ThingsWithObservation();
                            z.Name          = th.name;
                            z.Id            = (int)th.id;
                            z.Description   = th.descripton;
                            z.Status        = th.status;
                            z.Lat           = (decimal?)th.lat;
                            z.Lon           = (decimal?)th.lon;
                            z.ThingTemplate = th.ThingTemplate;
                            DBObservation dbo = new DBObservation();
                            List <IO.Swagger.Models.Observation> lo = new List <IO.Swagger.Models.Observation>();
                            if (dbo.ListObs((int)th.id, ref errorMessage, ref lo))
                            {
                                z.Observations = lo;
                            }
                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
Esempio n. 2
0
        public bool FindThingFromIdWithObs(string thingId, int?noOfObservations, ref string errorMessage, ref COP.API.Models.ThingsWithObservation results)
        {
            bool retVal = true;

            if (noOfObservations == null)
            {
                noOfObservations = 1;
            }
            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var things = (from d in context.Thing
                                  join f in context.ThingTemplates
                                  on d.Templateid equals f.Thingtemplateid
                                  where d.Thingid == long.Parse(thingId)
                                  select new
                    {
                        ogcid = d.Ogcid,
                        id = d.Thingid,
                        name = d.Name,
                        descripton = d.Description,
                        status = d.Status,
                        lat = d.Lat,
                        lon = d.Lon,
                        ThingTemplate = f.Name
                    }
                                  ).ToList();

                    if (things == null)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        results = new Models.ThingsWithObservation();
                        var th = things[0];
                        results.Name          = th.name;
                        results.Id            = (int)th.id;
                        results.Description   = th.descripton;
                        results.Status        = th.status;
                        results.Lat           = (decimal?)th.lat;
                        results.Lon           = (decimal?)th.lon;
                        results.ThingTemplate = th.ThingTemplate;
                        results.Ogcid         = th.ogcid;
                        DBObservation dbo = new DBObservation();
                        List <COP.API.Models.Observation> lo = new List <COP.API.Models.Observation>();
                        if (dbo.ListObs((int)th.id, (int)noOfObservations, ref errorMessage, ref lo))
                        {
                            results.Observations = lo;
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }