Exemplo n.º 1
0
        public async Task <Guid> Create(Models.Scene scen)
        {
            try
            {
                var context = CreateContext();
                var created = new Data.Scene
                {
                    Id               = scen.Id,
                    DateDebut        = scen.DateDebut,
                    DateFin          = scen.DateFin,
                    QueteId          = scen.QueteId,
                    SpotId           = scen.SpotId,
                    DescriptionScene = scen.DescriptionScene,
                };
                var enr = await context
                          ._Scene
                          .AddAsync(created);

                await context.SaveChangesAsync();

                return(enr.Entity.Id);
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
                return(scen.Id);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Turn switch/device ON
        /// </summary>
        private async void btnOnButton_Clicked(object sender, EventArgs e)
        {
            if (_viewModel.OldData)
            {
                return;
            }
            Button oButton = (Button)sender;

            Models.Scene oDevice = (Models.Scene)oButton.BindingContext;
            App.ShowToast(AppResources.switch_on + ": " + oDevice.Name);

            await App.ApiService.SetSwitch(oDevice.idx, true,
                                           oDevice.Type == ConstantValues.Device.Scene.Type.GROUP ||
                                           oDevice.Type == ConstantValues.Device.Scene.Type.SCENE);

            _viewModel.RefreshActionCommand.Execute(null);
        }
Exemplo n.º 3
0
        public async Task Delete(Models.Scene scen)
        {
            try
            {
                var context  = CreateContext();
                var toDelete = await context._Scene.FindAsync(scen.Id);

                if (toDelete != null)
                {
                    context._Scene.Remove(toDelete);
                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set Favorite
        /// </summary>
        private async Task SetFavorite(Models.Scene pair)
        {
            if (!pair.FavoriteBoolean)
            {
                App.ShowToast(pair.Name + " " + AppResources.favorite_added);
            }
            else
            {
                App.ShowToast(pair.Name + " " + AppResources.favorite_removed);
            }
            var result = await App.ApiService.SetFavorite(pair.idx, true, !pair.FavoriteBoolean);

            if (!result)
            {
                App.ShowToast(pair.Name + " " + AppResources.error_favorite);
            }

            _viewModel.RefreshFavoriteCommand.Execute(null);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Show a actionsheet on item selected
        /// </summary>
        private async void OnItemSelected(object sender, SelectedItemChangedEventArgs args)
        {
            var item = args.SelectedItem as Models.Scene;

            if (item == null)
            {
                return;
            }

            var actions = new List <string> {
                AppResources.favorite, AppResources.button_status_log
            };

            if (!string.IsNullOrEmpty(item.Timers) &&
                string.Compare(item.Timers, "true", StringComparison.OrdinalIgnoreCase) == 0)
            {
                actions.Add(AppResources.button_status_timer);
            }
            var tempDevice = new Models.Scene
            {
                idx  = item.idx,
                Type = item.Type,
                Name = item.Name
            };

            var result = await DisplayActionSheet(item.Name, AppResources.cancel, null, actions.ToArray());

            if (result == AppResources.favorite)
            {
                await SetFavorite(item);
            }
            else if (result == AppResources.button_status_log)
            {
                await PopupNavigation.Instance.PushAsync(new LogsPopup(tempDevice));
            }
            else if (result == AppResources.button_status_timer)
            {
                await PopupNavigation.Instance.PushAsync(new TimersPopup(tempDevice));
            }
            listView.SelectedItem = null;
        }
        /// <summary>
        /// Get scene template (group or scene)
        /// </summary>
        /// <param name="mDeviceInfo">The mDeviceInfo<see cref="Models.Scene"/></param>
        /// <returns>The <see cref="DataTemplate"/></returns>
        private DataTemplate GetSceneTemplate(Models.Scene mDeviceInfo)
        {
            if (mDeviceInfo == null)
            {
                return(null);
            }

            var oReturnvalue = DefaultTemplate;

            switch (mDeviceInfo.Type)
            {
            case ConstantValues.Device.Scene.Type.GROUP:
                oReturnvalue = App.AppSettings.ShowSwitches ? OnOffSwitchTemplate : OnOffButtonTemplate;
                break;

            case ConstantValues.Device.Scene.Type.SCENE:
                oReturnvalue = OnButtonTemplate;
                break;
            }

            return(oReturnvalue);
        }
Exemplo n.º 7
0
        public async Task Update(Models.Scene scen)
        {
            try
            {
                var context  = CreateContext();
                var toUpdate = await context._Scene.FindAsync(scen.Id);

                if (toUpdate != null)
                {
                    toUpdate.Id               = scen.Id;
                    toUpdate.DateDebut        = scen.DateDebut;
                    toUpdate.DateFin          = scen.DateFin;
                    toUpdate.QueteId          = scen.QueteId;
                    toUpdate.SpotId           = scen.SpotId;
                    toUpdate.DescriptionScene = scen.DescriptionScene;

                    await context.SaveChangesAsync();
                }
            }
            catch (DbUpdateException e)
            {
                Console.WriteLine(e.Message);
            }
        }