/************** Site ************/ public bool SiteAdd(Site site) { try { iotContext db = new iotContext(); iotDomain targetDomain = (from d in db.Domains where site.Domain.Id == d.Id select d).First(); Location siteLocation = (from l in db.Locations where l.Id == site.siteLocation.Id select l).First(); Site nsite = new Site(); nsite.SiteName = site.SiteName; nsite.Domain = targetDomain; nsite.siteLocation = siteLocation; db.Sites.Add(nsite); db.SaveChanges(); return(true); } catch (Exception e) { return(false); } }
public void Fake() { Location loc = new Location(); loc.Lat = 1.11; loc.Lng = 22.11; loc.LocationName = Guid.NewGuid().ToString(); this.Locations.Add(loc); this.SaveChanges(); Location storedloc = this.Locations.FirstOrDefault(nl => nl.LocationName == loc.LocationName); iotDomain d = new iotDomain(); d.DomainName = Guid.NewGuid().ToString(); d.Id = 0; d.Sites = new List <Site>(); this.Domains.Add(d); this.SaveChanges(); iotDomain stored = this.Domains.First(s => s.DomainName == d.DomainName); Site site = new Site(); site.Id = 0; site.Devices = new List <Device>(); site.Domain = stored; site.SiteName = Guid.NewGuid().ToString(); this.Sites.Add(site); this.SaveChanges(); }
public void Load(Site other) { this.Devices = other.Devices; this.Domain = other.Domain; this.Id = other.Id; this.SiteName = other.SiteName; this.siteLocation = other.siteLocation; }
public iotDomain DomainForDomainId(int domainId) { try { iotContext db = new iotContext(); iotDomain domain = (from d in db.Domains where d.Id.Equals(domainId) select d).First(); return(domain); } catch (Exception e) { return(new iotDomain()); } }
/**************************** Query ****************************/ /************** Domain ************/ public iotDomain DomainForDomainName(string name) { try { iotContext db = new iotContext(); iotDomain domain = (from d in db.Domains where d.DomainName == name select d).First(); return(domain); } catch (Exception e) { return(new iotDomain()); } }
/**************************** Execute ****************************/ /************** Domain ************/ public bool DomainAdd(iotDomain domain) { try { if (domain != null) { iotContext db = new iotContext(); db.Domains.Add(domain); db.SaveChanges(); //TODO verify save } } catch (Exception e) { } return(true); }
public iotContextBase(iotDomain domain) : this(DefaultDbConnStrName) { this.IotDomain = domain; }
public iotContext(iotDomain domain) : base(domain) { }