示例#1
0
        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);
        }
示例#2
0
        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));
        }
示例#3
0
        public string Import(string formName, string state, ImportContentContext importContext)
        {
            var describeContext = new DescribeContext();

            foreach (var provider in _formProviders)
            {
                provider.Describe(describeContext);
            }

            var descriptor = describeContext.Describe().FirstOrDefault(x => x.Name == formName);

            if (descriptor == null || descriptor.Import == null)
            {
                return(state);
            }

            var dynamicState = FormParametersHelper.ToDynamic(state);

            descriptor.Import(dynamicState, importContext);

            return(FormParametersHelper.ToString(dynamicState));
        }