Exemplo n.º 1
0
        public ActionResult List()
        {
            var userId = User.Identity.GetUserId();
            var userData = _uow.UserDataRepository.GetById(userId);

            var deviceViewList = new List<DeviceView>();

            var userDevices = userData.UserDevices;
            foreach (var userDevice in userDevices)
            {
                var device = userDevice.Device;
                var temperature = device.Temperatures.LastOrDefault(t => t.Time.Minute % userDevice.Period == 0);
                if (temperature == null)
                {
                    temperature= device.Temperatures.LastOrDefault();
                }

                var temperatureValue = temperature != null ? temperature.Value : 0;
                var time = temperature != null ? temperature.Time.ToShortTimeString() : DateTime.Now.ToShortTimeString();

                var newDeviceView = new DeviceView
                {
                    Id = device.Id,
                    LastTemparature = temperatureValue,
                    Time = time,
                    Profile = userDevice.Profile.Title,
                    Title = userDevice.Title,
                    Period = userDevice.Period
                };

                if (!userDevice.Profile.Intervals.Any(i => i.Start <= newDeviceView.LastTemparature && newDeviceView.LastTemparature <= i.End))
                {
                    newDeviceView.Status = "no";
                }
                else
                {
                    newDeviceView.Status = userDevice.Profile.Intervals.First(i => i.Start <= newDeviceView.LastTemparature && newDeviceView.LastTemparature <= i.End).Description;
                }

                deviceViewList.Add(newDeviceView);

            }

            return PartialView(deviceViewList);
        }
Exemplo n.º 2
0
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var userId = User.Identity.GetUserId();
            var userData = _uow.UserDataRepository.GetById(userId);
            var userDevice = userData.UserDevices.First(ud => ud.DeviceId.ToLowerInvariant() == id.ToLowerInvariant());
            if (userDevice == null)
            {
                return HttpNotFound();
            }

            var deviceView = new DeviceView
            {
                Id = userDevice.DeviceId,
                Title = userDevice.Title,
                Profile = userDevice.Profile.Title
            };

            return View(deviceView);
        }