public bool FindCameraCoords(string cameraName, ref string lat, ref string lon)
        {
            bool retVal = false;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var a = context.Thing.FirstOrDefault(Thing => Thing.Name == cameraName);
                    if (a != null)
                    {
                        lat = a.Lat.ToString().Replace(',', '.');
                        lon = a.Lon.ToString().Replace(',', '.');
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                return(false);
            }
            return(true);
        }
예제 #2
0
        public bool DeleteZone(string zonid, ref string errorMessage)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var loc = context.Location
                              .Single(b => b.Locationid == long.Parse(zonid));

                    if (loc == null)
                    {
                        errorMessage = "Non-Existing Location";
                        retVal       = false;
                    }
                    else
                    {
                        context.Location.Remove(loc);
                        context.SaveChanges();
                    }


                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #3
0
        public bool DeleteWearable(string personid, string thingid, ref string errorMessage)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var loc = context.PersonThings
                              .SingleOrDefault(b => b.Personid == long.Parse(personid) && b.Thingid == long.Parse(thingid)
                                               );

                    if (loc == null)
                    {
                        errorMessage = "Non-Existing WEARABLE";
                        retVal       = false;
                    }
                    else
                    {
                        context.PersonThings.Remove(loc);
                        context.SaveChanges();
                    }


                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #4
0
        public bool ListWearables(ref string errorMessage, ref List <COP.API.Models.Wearable> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    foreach (var loc in context.PersonThings)
                    {
                        COP.API.Models.Wearable z = new Models.Wearable();
                        z.PersonId  = loc.Personid;
                        z.ThingId   = (int?)loc.Thingid;
                        z.Timestamp = loc.Timepoint;
                        results.Add(z);
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #5
0
        public bool AddFeedbackType(string feedbackTypeName, string description, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    ProAcousticFeedbackTypes a = new ProAcousticFeedbackTypes();
                    a.Name        = feedbackTypeName;
                    a.Description = description;

                    context.ProAcousticFeedbackTypes.Add(a);
                    context.SaveChanges();

                    newid = a.Id;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #6
0
        public bool AddWearable(int?personid, int?thingid, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type

                    PersonThings a = new PersonThings();
                    a.Personid = (int)personid;
                    a.Thingid  = (int)thingid;



                    context.PersonThings.Add(a);
                    context.SaveChanges();

                    newid = 0;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #7
0
        public bool ValidateUserCredentials(ref string errorMessage, COP.API.Models.Login log)
        {
            bool retVal = false;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var loc = context.UserAuth
                              .SingleOrDefault(b => b.Username == log.Uid && b.Userpassword == log.Pwd);

                    if (loc == null)
                    {
                        errorMessage = "Failed Authorization";
                        retVal       = false;
                    }
                    else
                    {
                        retVal = true;
                    }


                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
        public bool AddOrUpdatePublicFeedback(string phoneid, string feedbacktype, double feedbackvalue, ref string errorMessage)
        {
            bool retVal = true;

            using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
            {
                //Find type
                try
                {
                    var obs = context.PublicFeedback
                              .Single(b => b.Phoneid == phoneid && b.FeedbackType == feedbacktype);


                    obs.Phoneid       = phoneid;
                    obs.FeedbackType  = feedbacktype;
                    obs.FeedbackValue = feedbackvalue;

                    context.SaveChanges();
                }
                catch (Exception f)
                {
                    COPDBContext.PublicFeedback lo = new COPDBContext.PublicFeedback();
                    lo.Phoneid       = phoneid;
                    lo.FeedbackType  = feedbacktype;
                    lo.FeedbackValue = feedbackvalue;
                    context.PublicFeedback.Add(lo);
                    context.SaveChanges();
                }
            }
            return(retVal);
        }
        public bool AddIncident(string description, string itype, string position, int prio, string status, double probability, string iplan, DateTime itime, string wid, string phoneno, string AdditionalMedia, string MediaType, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    Incident a = new Incident();
                    a.Description         = description;
                    a.Incidenttime        = itime;
                    a.Interventionplan    = iplan;
                    a.Position            = position;
                    a.Prio                = prio;
                    a.Probability         = probability;
                    a.Status              = status;
                    a.Type                = itype;
                    a.WearablePhysicalId  = wid;
                    a.PhoneNumber         = phoneno;
                    a.AdditionalMedia     = AdditionalMedia;
                    a.AdditionalMediaType = MediaType;
                    context.Incident.Add(a);
                    context.SaveChanges();

                    newid = a.Incidentid;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #10
0
        public bool TranslateNick(string wbid1, ref string nick)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var friend = (from d in context.FriendfinderReg

                                  where d.Id == wbid1
                                  select new
                                  { friendid = d.Id, nick = d.NickName }
                                  ).ToList();


                    foreach (var f in friend)
                    {
                        nick = f.nick;
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Database Exception:" + e.Message + " " + e.StackTrace);
                return(false);
            }
        }
예제 #11
0
        public bool AddFriend(string wbid1, string wbid2)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    Fffriends a = new Fffriends();
                    a.Friend1 = wbid1;
                    a.Friend2 = wbid2;
                    context.Fffriends.Add(a);
                    context.SaveChanges();


                    a         = new Fffriends();
                    a.Friend2 = wbid1;
                    a.Friend1 = wbid2;
                    context.Fffriends.Add(a);
                    context.SaveChanges();
                }
                return(retVal);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Database Exception:" + e.Message + " " + e.StackTrace);
                return(false);
            }
        }
예제 #12
0
        public bool GetEvent(ref string errorMessage, ref COP.API.Models.Event ev)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var a = context.Event.FirstOrDefault();
                    if (a != null)
                    {
                        ev       = new COP.API.Models.Event();
                        ev.Name  = a.Name;
                        ev.City  = a.Description;
                        ev.Lat   = (decimal)a.Lat;
                        ev.Lon   = (decimal)a.Lon;
                        ev.Zoom  = a.Zoom;
                        ev.Start = a.Fromdate;
                        ev.End   = a.Todate;
                    }
                    else
                    {
                        errorMessage = "Event info missing";
                        return(false);
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #13
0
        public bool AddImage(string imgUrl, string university, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    Image a = new Image();
                    a.Imgurl     = imgUrl;
                    a.University = university;


                    context.Image.Add(a);
                    context.SaveChanges();

                    newid = a.Id;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #14
0
        public bool FindThingFromId(string thingId, ref string errorMessage, ref COP.API.Models.Thing 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 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.Thing();
                        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.Ogcid         = th.ogcid;
                        results.ThingTemplate = th.ThingTemplate;
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #15
0
        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);
            }
        }
예제 #16
0
        public bool ListImages(string university, int take, ref string errorMessage, ref List <COP.API.Models.Image> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var imgs = (from d in context.Image
                                where d.University == university
                                orderby d.Id descending
                                select new
                                { id = d.Id, imgUrl = d.Imgurl, uni = d.University }
                                ).Take(take).ToList();

                    if (imgs == null)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var th in imgs)
                        {
                            COP.API.Models.Image z = new Models.Image();

                            z.Id     = (int)th.id;
                            z.ImgUrl = th.imgUrl;
                            if (th.uni == "LBU")
                            {
                                z.University = Models.Image.UniversityEnum.LBU;
                            }
                            else if (th.uni == "LUU")
                            {
                                z.University = Models.Image.UniversityEnum.LUU;
                            }
                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #17
0
        public bool WearablesPersonIdGet(string wbid, ref string errorMessage, ref List <COP.API.Models.Wearable> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var pp = (from d in context.Thing
                              where d.Ogcid == wbid
                              select d);

                    if (pp == null || pp.Count() == 0)
                    {
                        errorMessage = "Non existing wearable:" + wbid;
                        retVal       = false;
                    }
                    else
                    {
                        results = new List <Models.Wearable>();
                        foreach (var p in pp)
                        {
                            var wearable = (from a in context.Thing
                                            join h in context.PersonThings
                                            on a.Thingid equals h.Thingid
                                            where a.Thingid == p.Thingid
                                            select h);
                            foreach (var obs in wearable)
                            {
                                COP.API.Models.Wearable wb = new Models.Wearable();
                                wb.PersonId  = obs.Personid;
                                wb.ThingId   = (int)obs.Thingid;
                                wb.Timestamp = obs.Timepoint;

                                results.Add(wb);
                            }
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
        public bool ListProAcousticFeedback(string feedbackType, ref string errorMessage, ref List <COP.API.Models.ProAcousticFeedback> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var feedbacks = (from d in context.ProAcousticFeedback
                                     join f in context.ProAcousticFeedbackTypes
                                     on d.ProAcousticFeedbackType equals f.Id
                                     where f.Name == feedbackType
                                     select new
                                     { id = d.Id, lat = d.Lat, lon = d.Lon, textmessage = d.Textmessage, reportype = d.ReportType }
                                     ).ToList();

                    if (feedbacks == null)
                    {
                        errorMessage = "No feedbacks";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var loc in feedbacks)
                        {
                            COP.API.Models.ProAcousticFeedback z = new Models.ProAcousticFeedback();
                            z.FeedbackLat     = (decimal)loc.lat;
                            z.FeedbackLon     = (decimal)loc.lon;
                            z.FeedbackMessage = loc.textmessage;
                            z.FeedbackType    = feedbackType;
                            z.FeedbackValue   = (decimal)loc.reportype;

                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #19
0
        public bool ListProAcousticFeedbackTypes(ref string errorMessage, ref List <IO.Swagger.Models.ProAcousticFeedbackType> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var feedbackt = (from d in context.ProAcousticFeedbackTypes
                                     select new
                                     { id = d.Id, typeName = d.Name, description = d.Description }
                                     ).ToList();

                    if (feedbackt == null)
                    {
                        errorMessage = "No feedbacks";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var loc in feedbackt)
                        {
                            IO.Swagger.Models.ProAcousticFeedbackType z = new Models.ProAcousticFeedbackType();
                            z.Typeid                  = loc.id;
                            z.FeedbackTypeName        = loc.typeName;
                            z.FeedbackTypeDescription = loc.description;


                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #20
0
        //name.Name, name.ThingTemplate,name.Description, name.Status, name.Lat,name.Lon, ref errorMessage, ref newThingID
        public bool AddThing(string thingName, string type, string description, int?status, decimal?lat, decimal?lon, string Ogcid, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var ThingType = context.ThingTemplates
                                    .Single(b => b.Name == type);

                    if (ThingType == null)
                    {
                        errorMessage = "Non-Existing Role";
                        retVal       = false;
                    }
                    else
                    {
                        Thing a = new Thing();
                        a.Name        = thingName;
                        a.Templateid  = ThingType.Thingtemplateid;
                        a.Description = description;
                        a.Status      = (short)status;
                        a.Lat         = (double)lat;
                        a.Lon         = (double)lon;
                        a.Ogcid       = Ogcid;



                        context.Thing.Add(a);
                        context.SaveChanges();

                        newid = a.Thingid;
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #21
0
        public bool AddZone(string zoneName, string type, string description, string metadata, string boundingpolygon, int?capacity, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var LocationType = context.LocationTemplates
                                       .Single(b => b.Name == type);

                    if (LocationType == null)
                    {
                        errorMessage = "Non-Existing Role";
                        retVal       = false;
                    }
                    else
                    {
                        Location a = new Location();
                        a.Name = zoneName;
                        a.Locationtemplateid = LocationType.Locationtemplateid;
                        a.Description        = description;
                        a.Metadata           = metadata;
                        a.Boundingpolygon    = boundingpolygon;
                        if (capacity != null)
                        {
                            a.Capacity = capacity;
                        }

                        context.Location.Add(a);
                        context.SaveChanges();

                        newid = a.Locationid;
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #22
0
        public bool ListObs(int thingId, ref string errorMessage, ref List <IO.Swagger.Models.Observation> results)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var obs = (from d in context.LatestObservation  where d.Thingid == (long)thingId select d
                               ).ToList();

                    if (obs == null || obs.Count() == 0)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var th in obs)
                        {
                            IO.Swagger.Models.Observation z = new Models.Observation();
                            z.ThingId           = (int)th.Thingid;
                            z.DatastreamId      = th.Datastreamid;
                            z.Personid          = th.Personid;
                            z.Zoneid            = th.Locationid;
                            z.PhenomenTime      = th.Phenomentime;
                            z.ObservationResult = th.Observationresult;
                            results.Add(z);
                        }
                    }



                    //Insert role connection;
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #23
0
        public bool GetIncident(int id, ref string errorMessage, ref COP.API.Models.Incident inc)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var a = context.Incident.FirstOrDefault(Incident => Incident.Incidentid == id);
                    if (a != null)
                    {
                        inc                  = new COP.API.Models.Incident();
                        inc.Incidentid       = a.Incidentid;
                        inc.Description      = a.Description;
                        inc.Incidenttime     = a.Incidenttime;
                        inc.Interventionplan = a.Interventionplan;
                        inc.Position         = a.Position;
                        inc.Prio             = a.Prio;
                        inc.Probability      = (decimal)a.Probability;
                        inc.Status           = a.Status;
                        inc.Type             = a.Type;
                        inc.Wbid             = a.WearablePhysicalId;
                        inc.Telephone        = a.PhoneNumber;
                        inc.AdditionalMedia  = a.AdditionalMedia;
                        inc.MediaType        = a.AdditionalMediaType;
                        inc.Area             = a.Area;
                        context.Incident.Update(a);
                        context.SaveChanges();
                    }
                    else
                    {
                        errorMessage = "Incident with ID :" + id + "  does not exist";
                        return(false);
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #24
0
        public bool FindFriend(string wbid1, ref Models.FriendFinderList friends)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var friendList = (from d in context.Fffriends
                                      join e in context.FriendfinderReg
                                      on d.Friend2 equals e.Id
                                      where d.Friend1 == wbid1
                                      select new
                                      { friendid = d.Friend2, nick = e.NickName }
                                      ).ToList();

                    OGCSensorThings.GetFriendPositions fpos = new OGCSensorThings.GetFriendPositions();
                    foreach (var f in friendList)
                    {
                        //673458
                        COP.API.Models.FriendFinder z = new Models.FriendFinder();
                        z.NickName = f.nick;
                        string strLat   = "";
                        string strLon   = "";
                        string LastSeen = "";

                        if (fpos.GetFriendPostion(f.friendid, ref strLat, ref strLon, ref LastSeen))
                        {
                            z.Lat      = (decimal?)double.Parse(strLat, System.Globalization.CultureInfo.InvariantCulture);
                            z.Lon      = (decimal?)double.Parse(strLon, System.Globalization.CultureInfo.InvariantCulture);
                            z.LastSeen = LastSeen;
                            friends.Add(z);
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Database Exception:" + e.Message + " " + e.StackTrace);
                return(false);
            }
        }
        public bool AddFeedback(string feedbackTypeStr, string phoneid, string textmessage, double reporttype, double lat, double lon, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Find type
                    var FeedbackType = context.ProAcousticFeedbackTypes
                                       .Single(b => b.Name == feedbackTypeStr);

                    if (FeedbackType == null)
                    {
                        errorMessage = "Non-Existing Feedback type";
                        retVal       = false;
                    }
                    else
                    {
                        ProAcousticFeedback a = new ProAcousticFeedback();
                        a.ProAcousticFeedbackType = FeedbackType.Id;
                        a.ReportType  = reporttype;
                        a.Textmessage = textmessage;
                        a.Phoneid     = phoneid;
                        a.Lat         = lat;
                        a.Lon         = lon;


                        context.ProAcousticFeedback.Add(a);
                        context.SaveChanges();

                        newid = a.Id;
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Excaption:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #26
0
        public bool DBSendPersonMediaMessage(string PersonID, string mediaLink, string mediaType, ref string errormessage)
        {
            bool retVal      = false;
            int  intPersonID = int.Parse(PersonID);

            using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
            {
                var wearable = (from a in context.PersonThings
                                join f in context.Thing
                                on a.Thingid equals f.Thingid
                                join h in context.LatestObservation
                                on f.Thingid equals h.Thingid
                                where a.Personid == intPersonID && h.Personid == intPersonID
                                select f);
                foreach (var thing in wearable)
                {
                    string  thingId = thing.Ogcid;
                    dynamic jmsg    = new JObject();
                    dynamic payload = new JObject();
                    //{
                    //    "phenomenonTime":"2018-11-27T11:31:33.836Z","result":{
                    //            "tagId":"LumiereTestGlass",
                    //    "type":"text",
                    //    "message": "Hello World From CNet"
                    //   }
                    //}
                    jmsg.phenomenonTime = DateTime.UtcNow.ToString("O");
                    payload.tagId       = thingId;
                    payload.type        = mediaType;
                    payload.message     = mediaLink;
                    jmsg.result         = payload;
                    string mqttPayload      = jmsg.ToString();
                    MQTT.SendMQTTMessage mq = new MQTT.SendMQTTMessage();
                    mq.sendMqttMessage("GOST_LUMIERE_2019/Datastreams(28)/Observations", mqttPayload);
                    retVal = true;
                }
            }


            return(retVal);
        }
예제 #27
0
        public bool UpdateIncident(int id, string description, string itype, string position, int prio, string status, double probability, string iplan, DateTime itime, string wid, string phoneno, string AdditionalMedia, string MediaType, string Area, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    var a = context.Incident.FirstOrDefault(Incident => Incident.Incidentid == id);
                    if (a != null)
                    {
                        a.Description         = description;
                        a.Incidenttime        = itime;
                        a.Interventionplan    = iplan;
                        a.Position            = position;
                        a.Prio                = prio;
                        a.Probability         = probability;
                        a.Status              = status;
                        a.Type                = itype;
                        a.WearablePhysicalId  = wid;
                        a.PhoneNumber         = phoneno;
                        a.AdditionalMedia     = AdditionalMedia;
                        a.AdditionalMediaType = MediaType;
                        a.Area                = Area;
                        context.Incident.Update(a);
                        context.SaveChanges();
                    }
                    else
                    {
                        errorMessage = "Incident with ID :" + id + "  does not exist";
                        return(false);
                    }
                }
                return(retVal);
            }
            catch (Exception e)
            {
                errorMessage = "Database Exception:" + e.Message + " " + e.StackTrace;
                return(false);
            }
        }
예제 #28
0
        public bool Register(string wbid, string nickname)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    FriendfinderReg a = new FriendfinderReg();
                    a.Id       = wbid;
                    a.NickName = nickname;
                    context.FriendfinderReg.Add(a);
                    context.SaveChanges();
                }
                return(retVal);
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Database Exception:" + e.Message + " " + e.StackTrace);
                return(false);
            }
        }
예제 #29
0
        public bool AddUpdateObservation(int?thingid, string streamid, DateTime?phenomentime, string Observationresult, string type, int?personid, int?zoneid, ref string errorMessage, ref long newid)
        {
            bool retVal = true;

            using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
            {
                //Find type
                try
                {
                    var obs = context.LatestObservation
                              .Single(b => b.Thingid == thingid && b.Datastreamid == streamid);


                    obs.Thingid           = (long)thingid;
                    obs.Datastreamid      = streamid;
                    obs.Phenomentime      = phenomentime;
                    obs.Personid          = personid;
                    obs.Locationid        = zoneid;
                    obs.Observationresult = Observationresult;
                    obs.Type = type;
                    context.SaveChanges();
                }
                catch (Exception f)
                {
                    LatestObservation lo = new LatestObservation();
                    lo.Thingid           = (long)thingid;
                    lo.Datastreamid      = streamid;
                    lo.Phenomentime      = phenomentime;
                    lo.Observationresult = Observationresult;
                    lo.Personid          = personid;
                    lo.Locationid        = zoneid;
                    lo.Type = type;
                    context.LatestObservation.Add(lo);
                    context.SaveChanges();
                }
            }
            return(retVal);
        }
예제 #30
0
        public bool FindDataStreamId(int thingId, string streamType, ref string errorMessage, ref string datastreaminfo)
        {
            bool retVal = true;

            try
            {
                using (COPDBContext.monica_cnetContext context = new COPDBContext.monica_cnetContext())
                {
                    //Make query
                    var obs = (from d in context.LatestObservation where d.Thingid == (long)thingId && d.Type.Contains(streamType) select d
                               ).ToList();

                    if (obs == null || obs.Count() == 0)
                    {
                        errorMessage = "No things";
                        retVal       = false;
                    }
                    else
                    {
                        foreach (var th in obs)
                        {
                            datastreaminfo = th.Datastreamid;
                        }
                    }



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