Пример #1
0
        public void SendThermostatSettings(ThermostatUserEditRCModel thermostatRCModel)
        {
            var modelThermostat = new
            {
                SetTermostat = new Dictionary<string, object>()
            };
            modelThermostat.SetTermostat.Add("TermostatId", thermostatRCModel.Id);
            modelThermostat.SetTermostat.Add("TermostatState", thermostatRCModel.State);

            if (thermostatRCModel.State)
            {
                modelThermostat.SetTermostat.Add("Behavior", thermostatRCModel.Behavior);
                modelThermostat.SetTermostat.Add("TargetTemp", thermostatRCModel.TargetTemp);
            }
            this.Sender.SendMessageToReceiver(modelThermostat, thermostatRCModel.ReceiverIp);
        }
Пример #2
0
        public ActionResult EditThermostat(ThermostatViewModel thermostatViewModel)
        {
            if (ModelState.IsValid)
            {
                var editModel = this.Data.Thermostats.All()
                    .Where(t => t.Id == thermostatViewModel.Id)
                    .Select(s => new
                    {
                        Thermostat = s,
                        ReceiverIp = s.Room.Floor.House.ReceiverIp

                    }).SingleOrDefault();
                if (editModel == null)
                {
                    throw new HttpException(500, "No thermostat with this id");
                }
                editModel.Thermostat.State = thermostatViewModel.State;
                editModel.Thermostat.Behavior = thermostatViewModel.Behavior;
                editModel.Thermostat.TargetTemp = thermostatViewModel.TargetTemp;

                ThermostatUserEditRCModel thermostatUserEditRCModel = new ThermostatUserEditRCModel
                {
                    Id = editModel.Thermostat.ArduinoArrayTermostatId,
                    State = editModel.Thermostat.State,
                    TargetTemp = editModel.Thermostat.TargetTemp,
                    Behavior = editModel.Thermostat.Behavior,
                    ReceiverIp = editModel.ReceiverIp
                };

                using (TransactionScope transaction = new TransactionScope())
                {
                    this.Data.Thermostats.Update(editModel.Thermostat);
                    this.Data.SaveChanges();

                    this.RemoteControl.SendThermostatSettings(thermostatUserEditRCModel);
                    transaction.Complete();
                }
                return new HttpStatusCodeResult(200);
            }
            else
            {
                throw new HttpException(500, "The model is invalid");
            }
        }