Example #1
0
        public int AddDevicePing(int tenantId, DevicePingDomain device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device cannot be null");
            }

            if (tenantId <= 0)
            {
                throw new NsiArgumentException("Invalid tenant ID");
            }

            device.TenantId = tenantId;

            var devicePingDb = new NSI.EF.DevicePing().FromDomainModel(device);

            _context.DevicePing.Add(devicePingDb);

            // Set devicePingId to newly added record id
            device.DevicePropertyValues.ForEach(dpv => {
                dpv.DevicePingId = devicePingDb.DevicePingId;
                dpv.TenantId     = tenantId;
            });

            device.DevicePropertyValues.ForEach(devicePropertyValue =>
            {
                _context.DevicePropertyValue.Add((new NSI.EF.DevicePropertyValue()).FromDomainModel(devicePropertyValue));
            });

            _context.SaveChanges();

            return(devicePingDb.DevicePingId);
        }
Example #2
0
        public static NSI.EF.DevicePing FromDomainModel(this NSI.EF.DevicePing obj, DevicePingDomain domain)
        {
            if (obj == null)
            {
                obj = new NSI.EF.DevicePing();
            }

            obj.DevicePingId = domain.Id;
            obj.TenantId     = domain.TenantId;
            obj.RuleId       = domain.RuleId;
            obj.DateCreated  = domain.DateCreated;
            obj.ActionId     = domain.ActionId;
            obj.DeviceId     = domain.DeviceId;

            return(obj);
        }