public ActionResult Edit(int id, string category, string type, int filterId = -1) {
            if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to manage image profiles")))
                return new HttpUnauthorizedResult();

            var filter = _processingManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            if (filter == null) {
                return HttpNotFound();
            }

            // build the form, and let external components alter it
            var form = filter.Form == null ? null : _formManager.Build(filter.Form);

            string description = "";

            // bind form with existing values).
            if (filterId != -1) {
                var profile = _profileService.GetImageProfile(id);
                var filterRecord = profile.Filters.FirstOrDefault(f => f.Id == filterId);
                if (filterRecord != null) {
                    description = filterRecord.Description;
                    var parameters = FormParametersHelper.FromString(filterRecord.State);
                    _formManager.Bind(form, new DictionaryValueProvider<string>(parameters, CultureInfo.InvariantCulture));
                }
            }

            var viewModel = new FilterEditViewModel {Id = id, Description = description, Filter = filter, Form = form};
            return View(viewModel);
        }
        public ActionResult EditPost(int id, string category, string type, [DefaultValue(-1)] int filterId, FormCollection formCollection) {
            var profile = _profileService.GetImageProfile(id);

            var filter = _processingManager.DescribeFilters().SelectMany(x => x.Descriptors).FirstOrDefault(x => x.Category == category && x.Type == type);

            var model = new FilterEditViewModel();
            TryUpdateModel(model);

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

            if (ModelState.IsValid) {
                var filterRecord = profile.Filters.FirstOrDefault(f => f.Id == filterId);

                // add new filter record if it's a newly created filter
                if (filterRecord == null) {
                    filterRecord = new FilterRecord {
                        Category = category,
                        Type = type,
                        Position = profile.Filters.Count
                    };
                    profile.Filters.Add(filterRecord);
                }

                var dictionary = formCollection.AllKeys.ToDictionary(key => key, formCollection.Get);

                // save form parameters
                filterRecord.State = FormParametersHelper.ToString(dictionary);
                filterRecord.Description = model.Description;

                // set profile as updated
                profile.ModifiedUtc = DateTime.UtcNow;
                profile.FileNames.Clear();
                _signals.Trigger("MediaProcessing_" + profile.Name + "_Saved");

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

            // model is invalid, display it again
            var form = _formManager.Build(filter.Form);

            _formManager.Bind(form, formCollection);
            var viewModel = new FilterEditViewModel {Id = id, Description = model.Description, Filter = filter, Form = form};

            return View(viewModel);
        }