private bool CreateDelayedAction(ActionContext context) {
            var amount = Convert.ToInt32(context.Properties["Amount"]);
            var type = context.Properties["Unity"];
            var ruleId = Convert.ToInt32(context.Properties["RuleId"]);

            var scheduledActionTask = _contentManager.New("ScheduledActionTask").As<ScheduledActionTaskPart>();
            var rule = _repository.Get(ruleId);

            var when = _clock.UtcNow;

            switch (type) {
                case "Minute":
                    when = when.AddMinutes(amount);
                    break;
                case "Hour":
                    when = when.AddHours(amount);
                    break;
                case "Day":
                    when = when.AddDays(amount);
                    break;
                case "Week":
                    when = when.AddDays(7 * amount);
                    break;
                case "Month":
                    when = when.AddMonths(amount);
                    break;
                case "Year":
                    when = when.AddYears(amount);
                    break;
            }

            foreach (var action in rule.Actions) {
                var actionRecord = new ActionRecord {
                    Category = action.Category,
                    Position = action.Position,
                    Type = action.Type,
                    Parameters = _tokenizer.Replace(action.Parameters, context.Tokens)
                };

                _actionRecordRepository.Create(actionRecord);

                var scheduledAction = new ScheduledActionRecord { ActionRecord = actionRecord };
                _scheduledActionRecordRepository.Create(scheduledAction);

                scheduledActionTask.ScheduledActions.Add(scheduledAction);
            }


            _contentManager.Create(scheduledActionTask, VersionOptions.Draft);

            _scheduledTaskManager.CreateTask("TriggerRule", when, scheduledActionTask.ContentItem);

            return true;
        }
        public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)]int actionId, FormCollection formCollection) {
            var rule = _rulesServices.GetRule(id);

            var actionRecord = rule.Actions.Where(a => a.Id == actionId).FirstOrDefault();

            // add new action record if it's a newly created action
            if (actionRecord == null) {
                actionRecord = new ActionRecord { Category = category, Type = type, Position = rule.Actions.Count };
                rule.Actions.Add(actionRecord);
            }

            var action = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors).Where(x => x.Category == category && x.Type == type).FirstOrDefault();

            // validating form values
            _formManager.Validate(new ValidatingContext { FormName = action.Form, ModelState = ModelState, ValueProdiver = ValueProvider });

            if (ModelState.IsValid) {
                var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get);

                // save form parameters
                actionRecord.Parameters = FormParametersHelper.ToString(dictionary);

                return RedirectToAction("Edit", "Admin", new { id });
            }

            // model is invalid, display it again
            var form = _formManager.Build(action.Form);
            AddSubmitButton(form);
            _formManager.Bind(form, formCollection);
            var viewModel = new EditActionViewModel { Id = id, Action = action, Form = form };

            return View(viewModel);
        }