public async Task <IActionResult> EditData(string identifier, TimerTriggerViewModel data)
        {
            var result = await GetRecipeTrigger(identifier);

            if (result.Error != null)
            {
                return(result.Error);
            }

            if (data.TriggerEveryAmount <= 0)
            {
                ModelState.AddModelError(nameof(TimerTriggerViewModel.TriggerEveryAmount), "Amount needs to be at least 1");
            }

            if (!ModelState.IsValid)
            {
                return(View(data));
            }

            var recipeTrigger = result.Data;

            recipeTrigger.Set(data);

            await _recipeManager.AddOrUpdateRecipeTrigger(recipeTrigger);

            return(RedirectToAction("EditRecipe", "Recipes", new
            {
                id = recipeTrigger.RecipeId,
                statusMessage = "Invoice Timer trigger Updated"
            }));
        }
        public async Task <IActionResult> EditData(string identifier)
        {
            var result = await GetRecipeTrigger(identifier);

            if (result.Error != null)
            {
                return(result.Error);
            }

            var vm = new TimerTriggerViewModel(result.Data.Get <TimerTriggerParameters>(), result.Data.RecipeId);

            return(View(vm));
        }
示例#3
0
        protected override Task <(RecipeTrigger ToSave, TimerTriggerViewModel showViewModel)> BuildModel(
            TimerTriggerViewModel viewModel, RecipeTrigger mainModel)
        {
            if (viewModel.TriggerEveryAmount <= 0)
            {
                ModelState.AddModelError(nameof(TimerTriggerViewModel.TriggerEveryAmount),
                                         "Amount needs to be at least 1");
            }

            if (!ModelState.IsValid)
            {
                return(Task.FromResult <(RecipeTrigger ToSave, TimerTriggerViewModel showViewModel)>((null, viewModel)));
            }

            mainModel.Set((TimerTriggerParameters)viewModel);

            return(Task.FromResult <(RecipeTrigger ToSave, TimerTriggerViewModel showViewModel)>((mainModel, null)));
        }
示例#4
0
        public static BaseTriggerViewModel GetViewModelForTrigger(BaseTrigger trigger)
        {
            BaseTriggerViewModel vm = null;

            switch (trigger.GetType().Name)
            {
            case "KeysDownTrigger":
            {
                vm = new KeysTriggerViewModel((KeysDownTrigger)trigger);
                break;
            }

            case "KeysUpTrigger":
            {
                vm = new KeysTriggerViewModel((KeysUpTrigger)trigger);
                break;
            }

            case "KeysHoldingOnce":
            {
                vm = new KeysTriggerViewModel((KeysHoldingOnce)trigger);
                break;
            }

            case "KeysHolding":
            {
                vm = new KeysTriggerViewModel((KeysHoldingTrigger)trigger);
                break;
            }

            case "OnAddCallbackTrigger":
            {
                vm = new OnAddCallbackTriggerViewModel((OnAddCallbackTrigger)trigger);
                break;
            }

            case "TimerTrigger":
            {
                vm = new TimerTriggerViewModel((TimerTrigger)trigger);
                break;
            }

            case "AnyKeyDown":
            {
                vm = new AnyKeyDownViewModel((AnyKeyDownTrigger)trigger);
                break;
            }

            case "AnyKeyUp":
            {
                vm = new AnyKeyUpViewModel((AnyKeyUpTrigger)trigger);
                break;
            }

            case "OnExitTrigger":
            {
                vm = new OnExitTriggerViewModel((OnExitTrigger)trigger);
                break;
            }

            case "MouseMoveTrigger":
            {
                vm = new MouseMoveTriggerViewModel((MouseMoveTrigger)trigger);
                break;
            }

            case "MouseDownTrigger":
            {
                vm = new MouseDownTriggerViewModel((MouseDownTrigger)trigger);
                break;
            }

            case "MouseUpTrigger":
            {
                vm = new MouseUpTriggerViewModel((MouseUpTrigger)trigger);
                break;
            }

            default:
            {
                throw new TriggersExeptions.UnknownTriggerTypeExeption(trigger.GetType());
            }
            }
            return(vm);
        }