Beispiel #1
0
        public ActionResult EditPost(EditRuleViewModel viewModel)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage rules")))
            {
                return(new HttpUnauthorizedResult());
            }

            if (!ModelState.IsValid)
            {
                Services.TransactionManager.Cancel();
            }
            else
            {
                var rule = _rulesServices.GetRule(viewModel.Id);
                rule.Name    = viewModel.Name;
                rule.Enabled = viewModel.Enabled;

                Services.Notifier.Information(T("Rule Saved"));
                return(RedirectToAction("Edit", new { id = rule.Id }));
            }

            return(View(viewModel));
        }
Beispiel #2
0
 public ActionResult EditAndEnablePost(EditRuleViewModel viewModel)
 {
     viewModel.Enabled = true;
     return(EditPost(viewModel));
 }
Beispiel #3
0
 public EditRuleView()
 {
     InitializeComponent();
     DataContext = new EditRuleViewModel();
 }
Beispiel #4
0
        public ActionResult Edit(int id)
        {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to edit rules")))
            {
                return(new HttpUnauthorizedResult());
            }

            var rule      = _rulesServices.GetRule(id);
            var viewModel = new EditRuleViewModel {
                Id      = rule.Id,
                Enabled = rule.Enabled,
                Name    = rule.Name
            };

            #region Load events
            var eventEntries = new List <EventEntry>();
            var allEvents    = _rulesManager.DescribeEvents().SelectMany(x => x.Descriptors);

            foreach (var eventRecord in rule.Events)
            {
                var category = eventRecord.Category;
                var type     = eventRecord.Type;

                var ev = allEvents.Where(x => category == x.Category && type == x.Type).FirstOrDefault();
                if (ev != null)
                {
                    var eventParameters = FormParametersHelper.FromString(eventRecord.Parameters);
                    eventEntries.Add(
                        new EventEntry {
                        Category      = ev.Category,
                        Type          = ev.Type,
                        EventRecordId = eventRecord.Id,
                        DisplayText   = ev.Display(new EventContext {
                            Properties = eventParameters
                        })
                    });
                }
            }

            viewModel.Events = eventEntries;

            #endregion

            #region Load actions
            var actionEntries = new List <ActionEntry>();
            var allActions    = _rulesManager.DescribeActions().SelectMany(x => x.Descriptors);

            foreach (var actionRecord in rule.Actions.OrderBy(x => x.Position))
            {
                var category = actionRecord.Category;
                var type     = actionRecord.Type;

                var action = allActions.Where(x => category == x.Category && type == x.Type).FirstOrDefault();
                if (action != null)
                {
                    var actionParameters = FormParametersHelper.FromString(actionRecord.Parameters);
                    actionEntries.Add(
                        new ActionEntry {
                        Category       = action.Category,
                        Type           = action.Type,
                        ActionRecordId = actionRecord.Id,
                        DisplayText    = action.Display(new ActionContext {
                            Properties = actionParameters
                        })
                    });
                }
            }

            viewModel.Actions = actionEntries;
            #endregion

            return(View(viewModel));
        }
 public ActionResult Edit(EditRuleViewModel model)
 {
     return(View());
 }