Пример #1
0
 public void SendDeviceSettings(DeviceRCModel deviceRCModel)
 {
     this.Sender.SendMessageToReceiver(new
     {
         SetDevice = new
         {
             Pin = deviceRCModel.Pin,
             State = deviceRCModel.State
         }
     }, deviceRCModel.ReceiverIp);
 }
Пример #2
0
        public ActionResult Create(DeviceCreateViewModel deviceCreateViewModel)
        {
            if (ModelState.IsValid)
            {
                Device device = new Device
                {
                    AttachedPin = deviceCreateViewModel.AttachedPin,
                    Name = deviceCreateViewModel.Name,
                    RoomId = deviceCreateViewModel.RoomId,
                    State = deviceCreateViewModel.State
                };

                string ReceiverIp = this.Data.Rooms.All()
                    .Where(r => r.Id == deviceCreateViewModel.RoomId)
                    .Select(s => s.Floor.House.ReceiverIp)
                    .SingleOrDefault();
                if (ReceiverIp == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                DeviceRCModel deviceRCModel = new DeviceRCModel
                {
                    ReceiverIp = ReceiverIp,
                    Pin = deviceCreateViewModel.AttachedPin,
                    State = deviceCreateViewModel.State,
                };

                using (TransactionScope transaction = new TransactionScope())
                {
                    this.Data.Devices.Add(device);
                    this.Data.SaveChanges();
                    this.RemoteControl.SendDeviceSettings(deviceRCModel);
                    transaction.Complete();
                }

                return RedirectToAction("RoomDetails", "Rooms", new { RoomId = device.RoomId });
            }
            return View(deviceCreateViewModel);
        }