public object Patch(string id, [FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } var redId = new RedirectId(id); Site site = redId.SiteId == null ? null : SiteHelper.GetSite(redId.SiteId.Value); if (redId.SiteId != null && site == null) { return(NotFound()); } string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model); HttpRedirectSection section = RedirectHelper.GetRedirectSection(site, redId.Path, configPath); RedirectHelper.UpdateFeatureSettings(model, section); ManagementUnit.Current.Commit(); return(RedirectHelper.ToJsonModel(site, redId.Path)); }
public static void UpdateFeatureSettings(dynamic model, HttpRedirectSection section) { try { DynamicHelper.If <bool>((object)model.enabled, v => section.Enabled = v); DynamicHelper.If <bool>((object)model.preserve_filename, v => section.ChildOnly = v); DynamicHelper.If((object)model.destination, v => section.Destination = v); DynamicHelper.If <bool>((object)model.absolute, v => section.ExactDestination = v); DynamicHelper.If <int>((object)model.status_code, v => section.HttpResponseStatus = (RedirectHttpResponseStatus)v); if (model.metadata != null) { DynamicHelper.If <OverrideMode>((object)model.metadata.override_mode, v => section.OverrideMode = v); } } catch (FileLoadException e) { throw new LockedException(section.SectionPath, e); } catch (DirectoryNotFoundException e) { throw new ConfigScopeNotFoundException(e); } }