public ActionResult Edit(DeviceEntity model) { var device = _deviceRepository.Get(model.Id); if (null == device || device.OrganizationId != CurrentOrganization.Id) { return(HttpNotFound()); } var roomId = (model.ControlledRoomIds ?? new string[0]).FirstOrDefault(); var room = roomId == null ? null : _roomMetadataRepository.GetRoomInfo(roomId); if ((model.ControlledRoomIds ?? new string[0]).Any() && (null == room || room.OrganizationId != CurrentOrganization.Id)) { return(HttpNotFound()); } device.ControlledRoomIds = model.ControlledRoomIds; device.WarnNonStartedMeetingDelay = model.WarnNonStartedMeetingDelay; device.AutoCancelNonStartedMeetingDelay = model.AutoCancelNonStartedMeetingDelay; device.BuildingId = room?.BuildingId; _deviceRepository.Update(device); _broadcastService.BroadcastDeviceChange(CurrentOrganization, device); return(RedirectToAction("Index")); }