Example #1
0
        internal void SaveValue(DTOs.External.DeviceValue value)
        {
            tKovanContext ctx = new tKovanContext();

            Models.EntityClass.DeviceValue deviceValue = new Models.EntityClass.DeviceValue();

            deviceValue = Utilities.Map <TeknolojiKovaniWebApi.Domain.Values.DTOs.External.DeviceValue, TeknolojiKovaniWebApi.Models.EntityClass.DeviceValue>(value, deviceValue);

            deviceValue.DataServerTime = DateTime.UtcNow.AddHours(3);
            deviceValue.DataDeviceTime = DateTime.UtcNow.AddHours(3);

            ProfileDomain profileDomain = new ProfileDomain();
            PropertyRead  property      = profileDomain.GetProperty(value.PropertyName);

            deviceValue.PropertyId = property.Id;

            DeviceDomain deviceDomain = new DeviceDomain();
            DeviceRead   device       = deviceDomain.GetDevice(value.DeviceId);

            deviceValue.EnvironmentId = device.EnvironmentId.Value;
            deviceValue.UserId        = device.UserId;

            ctx.DeviceValue.Add(deviceValue);
            ctx.SaveChanges();
        }
Example #2
0
        public List <DTOs.DeviceLastValue> GetAllDeviceAndLastStatus(int UserId)
        {
            tKovanContext ctx = new tKovanContext();
            List <DTOs.DeviceLastValue>      DeviceLastValueList = new List <DTOs.DeviceLastValue>();
            List <Models.EntityClass.Device> Device = ctx.Device.Include("Profile").Include("Profile.SensorProfiles").Include("Profile.SensorProfiles.Sensor").Include("Profile.SensorProfiles.Sensor.Properties").Where(x => x.UserId == UserId).ToList();

            foreach (Models.EntityClass.Device itemDevice in Device)
            {
                if (itemDevice.Profile.SensorProfiles != null)
                {
                    foreach (Models.EntityClass.SensorProfile itemSensorProfile in itemDevice.Profile.SensorProfiles.ToList())
                    {
                        if (itemSensorProfile.Sensor.Properties != null)
                        {
                            foreach (Models.EntityClass.Property itemProperty in itemSensorProfile.Sensor.Properties)
                            {
                                DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue();
                                tDeviceLastValue.Id           = itemDevice.Id;
                                tDeviceLastValue.DeviceName   = itemDevice.Name;
                                tDeviceLastValue.PropertyId   = itemProperty.Id;
                                tDeviceLastValue.PropertyName = itemProperty.DisplayName;
                                Models.EntityClass.DeviceValue DeviceLastValue = ctx.DeviceValue.Where(x => x.PropertyId == itemProperty.Id && x.DeviceId == itemDevice.Id).OrderByDescending(x => x.DataDeviceTime).FirstOrDefault();
                                if (DeviceLastValue != null)
                                {
                                    tDeviceLastValue.Value          = DeviceLastValue.Value;
                                    tDeviceLastValue.DataDeviceTime = DeviceLastValue.DataDeviceTime;
                                }
                                DeviceLastValueList.Add(tDeviceLastValue);
                            }
                        }
                        else
                        {
                            DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue();
                            tDeviceLastValue.Id             = itemDevice.Id;
                            tDeviceLastValue.DeviceName     = itemDevice.Name;
                            tDeviceLastValue.PropertyName   = "Tanımlı Property Yok";
                            tDeviceLastValue.Value          = 0;
                            tDeviceLastValue.DataDeviceTime = new DateTime(1900, 1, 1);
                            DeviceLastValueList.Add(tDeviceLastValue);
                        }
                    }
                }
                else
                {
                    DTOs.DeviceLastValue tDeviceLastValue = new DTOs.DeviceLastValue();
                    tDeviceLastValue.Id             = itemDevice.Id;
                    tDeviceLastValue.DeviceName     = itemDevice.Name;
                    tDeviceLastValue.PropertyName   = "Tanımlı Sensör Yok";
                    tDeviceLastValue.Value          = 0;
                    tDeviceLastValue.DataDeviceTime = new DateTime(1900, 1, 1);
                    DeviceLastValueList.Add(tDeviceLastValue);
                }
            }
            return(DeviceLastValueList);
        }