示例#1
0
        private static async Task ControlDevice(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case ENCENDER:
            case APAGAR:
                ControlQueue controlQueueDesactivar = new ControlQueue()
                {
                    ControlId  = session.SelectedControl.ControlId,
                    InsertedAt = DateTime.UtcNow,
                    Value      = session.CurrentMessage == ENCENDER ? 1 : 0
                };
                await DataService.ControlQueues.InsertControlQueue(controlQueueDesactivar);

                await TelegramBotManager.SendMessage(session.ChatId, $"El control ({session.SelectedControl.KeyItem}) ha sido {(session.CurrentMessage == ENCENDER ? "encendido" : "apagado")}, Que deseas realizar?", ControlMenuKeyboard);

                session.Status = ChatStatus.CONTROL_SELECTED;
                break;

            case REGRESAR:
                await TelegramBotManager.SendMessage(session.ChatId, $"Control seleccionado ({session.SelectedControl.KeyItem})", ControlMenuKeyboard);

                session.Status = ChatStatus.CONTROL_SELECTED;
                break;


            default:
                await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                break;
            }
        }
示例#2
0
        private static async Task ControlSelected(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case CONTROLAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Que accion deseas realizar?", ControlDeviceMenu);

                session.Status = ChatStatus.CONTROL_DEVICE;
                break;

            case ACTUALIZAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Cual sera el nuevo nombre del Control?");

                session.Status = ChatStatus.CONTROL_RENAMING;
                break;

            case REGRESAR:
                session.SelectedControl = null;
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem})", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
                break;

            case ELIMINAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Estas seguro que deseas eliminar este control?", SiNoKeyboard);

                session.Status = ChatStatus.CONTROL_ASK_ELIMINATION;
                break;

            default:
                await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                break;
            }
        }
示例#3
0
        private static async Task Devices(ChatSession session)
        {
            User usr;

            if (session.CurrentMessage == ANADIR_DISPOSITIVO)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu dispositivo?");

                session.Status = ChatStatus.ADD_DEVICE;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await UserExists(session);
            }
            else
            {
                usr = await DataService.Users.FindUserByUsername(session.Username);

                var devices = await DataService.Devices.DevicesByUser(usr.UserId);

                int option = IntOption(session.CurrentMessage);

                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Device dev = devices.FirstOrDefault(f => f.DeviceId == option);

                if (dev == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }

                session.SelectedDevice = dev;
                session.Status         = ChatStatus.DEVICE_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem}), que deseas realizar", DeviceMenuKeyboard);
            }
        }
示例#4
0
        private static async Task Watches(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_WATCH)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu watch?");

                session.IsUpdatingWatch = false;
                session.Status          = ChatStatus.WATCH_NAMING;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Metrica ({session.SelectedMetric.KeyItem}), que deseas realizar?", MetricsMenuKeyboard);

                session.Status = ChatStatus.METRIC_SELECTED;
            }
            else
            {
                var watches = await DataService.Watches.WatchesByMetric(session.SelectedMetric.MetricId);

                int option = IntOption(session.CurrentMessage);

                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Watch watch = watches.FirstOrDefault(f => f.WatchId == option);

                if (watch == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese watch");

                    return;
                }

                session.SelectedWatch = watch;
                session.Status        = ChatStatus.WATCH_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Watch seleccionado ({session.SelectedWatch.KeyItem}), que deseas realizar", WatchesMenuKeyboard);
            }
        }
示例#5
0
        private static async Task DeviceMetrics(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_METRICA)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu nueva metrica?");

                session.IsUpdatingMetric = false;
                session.Status           = ChatStatus.METRIC_NAMING;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.Name}), que accion deseas realizar", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
            }
            else
            {
                var metrics = await DataService.Metrics.MetricsByDevice(session.SelectedDevice.DeviceId);

                int option = IntOption(session.CurrentMessage);
                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Metric metric = metrics.FirstOrDefault(f => f.MetricId == option);
                if (metric == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }
                session.SelectedMetric = metric;
                session.Status         = ChatStatus.METRIC_SELECTED;
                await TelegramBotManager.SendMessage(session.ChatId, "Dispositivo seleccionado, que deseas realizar", MetricsMenuKeyboard);
            }
        }
示例#6
0
        private static async Task DeviceControls(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_CONTROL)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre del nuevo control?");

                session.Status = ChatStatus.ADD_CONTROL;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem}) que accion deseas realizar", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
            }
            else
            {
                var controls = await DataService.Controls.ControlsByDevice(session.SelectedDevice.DeviceId);

                int option = IntOption(session.CurrentMessage);
                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }
                Control control = controls.FirstOrDefault(f => f.ControlId == option);
                if (control == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }
                session.SelectedControl = control;
                session.Status          = ChatStatus.CONTROL_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Control seleccionado ({session.SelectedControl.KeyItem}), que deseas realizar", ControlMenuKeyboard);
            }
        }