public bool DeviceTypeAdd(DeviceType type)
 {
     try
     {
         iotSharedEntityContext <DeviceType> cont = new iotSharedEntityContext <DeviceType>();
         cont.Add(type);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        /**************************** Get ****************************/

        public List <Site> GetSitesInDomain(int DomainId)
        {
            try
            {
                iotSharedEntityContext <Site> cont = new iotSharedEntityContext <Site>();
                List <Site> sites = cont.GetAll().Where(s => s.Domain.Id == DomainId).ToList();
                return(sites);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(new List <Site>());
            }
        }
 public bool PropertyResultParamAdd(DeviceParameter param)
 {
     try
     {
         iotSharedEntityContext <DeviceParameter> cont = new iotSharedEntityContext <DeviceParameter>();
         cont.Add(param);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ActionRequiredParamAdd(ActionParameter param)
 {
     try
     {
         iotSharedEntityContext <ActionParameter> cont = new iotSharedEntityContext <ActionParameter>();
         cont.Add(param);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool PropertyAdd(DeviceProperty prop)
 {
     try
     {
         iotSharedEntityContext <DeviceProperty> cont = new iotSharedEntityContext <DeviceProperty>();
         cont.Add(prop);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool LocationAdd(Location loc)
 {
     try
     {
         iotSharedEntityContext <Location> cont = new iotSharedEntityContext <Location>();
         cont.Add(loc);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool AddSiteToDomain(Site site)
 {
     try
     {
         iotSharedEntityContext <Site> cont = new iotSharedEntityContext <Site>();
         cont.Add(site);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool AddActionToDeviceAtSiteInDomain(DeviceAction action)
 {
     try
     {
         iotSharedEntityContext <DeviceAction> cont = new iotSharedEntityContext <DeviceAction>();
         cont.Add(action);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool DeviceCredentialsRemove(DeviceCredentials creds)
 {
     try
     {
         iotSharedEntityContext <DeviceCredentials> propCont = new iotSharedEntityContext <DeviceCredentials>();
         propCont.Delete(creds);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool EndpointRemove(EndpointInfo endp)
 {
     try
     {
         iotSharedEntityContext <EndpointInfo> propCont = new iotSharedEntityContext <EndpointInfo>();
         propCont.Delete(endp);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ReqParamRemove(ActionParameter actparam)
 {
     try
     {
         iotSharedEntityContext <ActionParameter> propCont = new iotSharedEntityContext <ActionParameter>();
         propCont.Delete(actparam);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool LocationRemove(Location location)
 {
     try
     {
         iotSharedEntityContext <Location> propCont = new iotSharedEntityContext <Location>();
         propCont.Delete(location);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool PropertyRemove(DeviceProperty property)
 {
     try
     {
         iotSharedEntityContext <DeviceProperty> propCont = new iotSharedEntityContext <DeviceProperty>();
         propCont.Delete(property);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool SiteRemove(Site Site)
 {
     try
     {
         iotSharedEntityContext <Site> propCont = new iotSharedEntityContext <Site>();
         propCont.Delete(Site);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool DeviceTypeUpdate(DeviceType type)
 {
     try
     {
         iotSharedEntityContext <DeviceType> propCont = new iotSharedEntityContext <DeviceType>();
         propCont.UpdateWithHistory(type);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        /*********************** Delete ***********************/


        public bool DomainRemove(iotDomain domain)
        {
            try
            {
                iotSharedEntityContext <iotDomain> propCont = new iotSharedEntityContext <iotDomain>();
                propCont.Delete(domain);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
 public bool LocationUpdate(Location Location)
 {
     try
     {
         iotSharedEntityContext <Location> propCont = new iotSharedEntityContext <Location>();
         propCont.UpdateWithHistory(Location);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool ReqParamUpdate(ActionParameter param)
 {
     try
     {
         iotSharedEntityContext <ActionParameter> propCont = new iotSharedEntityContext <ActionParameter>();
         propCont.UpdateWithHistory(param);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool SiteUpdate(Site site)
 {
     try
     {
         iotSharedEntityContext <Site> propCont = new iotSharedEntityContext <Site>();
         propCont.UpdateWithHistory(site);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public bool PropertyUpdate(DeviceProperty Property)
 {
     try
     {
         iotSharedEntityContext <DeviceProperty> propCont = new iotSharedEntityContext <DeviceProperty>();
         propCont.UpdateWithHistory(Property);
         return(true);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
        /*********************** Update ***********************/


        public bool DomainUpdate(iotDomain domain)
        {
            try
            {
                iotSharedEntityContext <iotDomain> cont = new iotSharedEntityContext <iotDomain>();
                iotDomain updated = cont.GetById(domain.Id); //db.GetById(domain.DomainName);
                cont.UpdateWithHistory(domain);              //db.UpdateById(domain, domain.DomainName);
                return(true);
            }
            catch (Exception e)
            {
                nlogger.ErrorException(e.Message, e);
                return(false);
            }
        }
 public bool DeviceUpdate(Device device)
 {
     try
     {
         iotSharedEntityContext <Device> propCont = new iotSharedEntityContext <Device>();
         propCont.UpdateWithHistory(device);
         return(true);
         // Task updateTask = Task.Factory.StartNew(() => { DeviceUpdateEventService.SendDeviceUpdate(device); }); //Dispatch update notify
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(false);
     }
 }
 public List <Device> GetAllDevices()
 {
     try
     {
         iotSharedEntityContext <Device> propCont = new iotSharedEntityContext <Device>();
         List <Device> stored = propCont.GetAll().ToList();
         if (stored != null)
         {
             return(stored);
         }
         return(null);
     }
     catch (Exception e)
     {
         return(null);
     }
 }
 public DeviceParameter DeviceParameterWithId(int ParamId)
 {
     try
     {
         iotSharedEntityContext <DeviceParameter> devCont = new iotSharedEntityContext <DeviceParameter>();
         DeviceParameter dev = devCont.GetById(ParamId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new DeviceParameter());
     }
 }
 public EndpointInfo EndpointWithId(int EndpId)
 {
     try
     {
         iotSharedEntityContext <EndpointInfo> devCont = new iotSharedEntityContext <EndpointInfo>();
         EndpointInfo dev = devCont.GetById(EndpId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new EndpointInfo());
     }
 }
 public DeviceCredentials DeviceCredentialWithId(int CredId)
 {
     try
     {
         iotSharedEntityContext <DeviceCredentials> devCont = new iotSharedEntityContext <DeviceCredentials>();
         DeviceCredentials dev = devCont.GetById(CredId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new DeviceCredentials());
     }
 }
 public ActionParameter ActionParamWithId(int ActionId)
 {
     try
     {
         iotSharedEntityContext <ActionParameter> devCont = new iotSharedEntityContext <ActionParameter>();
         ActionParameter dev = devCont.GetById(ActionId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new ActionParameter());
     }
 }
 public DeviceType DeviceTypeWithId(int TypeId)
 {
     try
     {
         iotSharedEntityContext <DeviceType> devCont = new iotSharedEntityContext <DeviceType>();
         DeviceType dev = devCont.GetById(TypeId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new DeviceType());
     }
 }
 public Location LocationWithId(int LocationId)
 {
     try
     {
         iotSharedEntityContext <Location> devCont = new iotSharedEntityContext <Location>();
         Location dev = devCont.GetById(LocationId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new Location());
     }
 }
 public iotDomain DomainWithId(int DomainId)
 {
     try
     {
         iotSharedEntityContext <iotDomain> devCont = new iotSharedEntityContext <iotDomain>();
         iotDomain dev = devCont.GetById(DomainId);
         if (dev != null)
         {
             return(dev);
         }
         return(null);
     }
     catch (Exception e)
     {
         nlogger.ErrorException(e.Message, e);
         return(new iotDomain());
     }
 }