public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } if (model.handler == null || !(model.handler is JObject)) { throw new ApiArgumentException("handler"); } string handlersUuid = DynamicHelper.Value(model.handler.id); if (handlersUuid == null) { throw new ApiArgumentException("handler.id"); } // Get the feature id HandlersId handlersId = new HandlersId(handlersUuid); Site site = handlersId.SiteId == null ? null : SiteHelper.GetSite(handlersId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); HandlersSection section = HandlersHelper.GetHandlersSection(site, handlersId.Path, configPath); Mapping mapping = MappingsHelper.CreateMapping(model, section); MappingsHelper.AddMapping(mapping, section); ManagementUnit.Current.Commit(); dynamic m = MappingsHelper.ToJsonModel(mapping, site, handlersId.Path); return(Created(MappingsHelper.GetLocation(m.id), m)); }
public object Patch(string id, [FromBody] dynamic model) { MappingId mappingId = new MappingId(id); Site site = mappingId.SiteId == null ? null : SiteHelper.GetSite(mappingId.SiteId.Value); if (mappingId.SiteId != null && site == null) { return(NotFound()); } string configPath = ManagementUnit.ResolveConfigScope(model); HandlersSection section = HandlersHelper.GetHandlersSection(site, mappingId.Path, configPath); Mapping mapping = section.Mappings.FirstOrDefault(u => u.Name.Equals(mappingId.Name)); if (mapping == null) { return(NotFound()); } MappingsHelper.UpdateMapping(model, mapping, section); ManagementUnit.Current.Commit(); // // Create response dynamic m = MappingsHelper.ToJsonModel(mapping, site, mappingId.Path); if (m.id != id) { return(LocationChanged(MappingsHelper.GetLocation(m.id), m)); } return(m); }
public object Patch(string id, [FromBody] dynamic model) { HandlersId handlersId = new HandlersId(id); Site site = handlersId.SiteId == null ? null : SiteHelper.GetSite(handlersId.SiteId.Value); if (handlersId.SiteId != null && site == null) { return(NotFound()); } if (model == null) { throw new ApiArgumentException("model"); } // Check for config_scope string configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);; HandlersSection section = HandlersHelper.GetHandlersSection(site, handlersId.Path, configPath); HandlersHelper.UpdateFeatureSettings(model, section); ManagementUnit.Current.Commit(); return(HandlersHelper.ToJsonModel(site, handlersId.Path)); }
public void Delete(string id) { HandlersId handlersId = new HandlersId(id); Context.Response.StatusCode = (int)HttpStatusCode.NoContent; Site site = (handlersId.SiteId != null) ? SiteHelper.GetSite(handlersId.SiteId.Value) : null; if (site == null) { return; } HandlersSection section = HandlersHelper.GetHandlersSection(site, handlersId.Path, ManagementUnit.ResolveConfigScope()); section.RevertToParent(); ManagementUnit.Current.Commit(); }
public void Delete(string id) { MappingId mappingId = new MappingId(id); Site site = mappingId.SiteId == null ? null : SiteHelper.GetSite(mappingId.SiteId.Value); if (mappingId.SiteId != null && site == null) { Context.Response.StatusCode = (int)HttpStatusCode.NoContent; return; } Mapping mapping = MappingsHelper.GetMappings(site, mappingId.Path).FirstOrDefault(u => u.Name.Equals(mappingId.Name)); if (mapping != null) { var section = HandlersHelper.GetHandlersSection(site, mappingId.Path, ManagementUnit.ResolveConfigScope()); MappingsHelper.DeleteMapping(mapping, section); ManagementUnit.Current.Commit(); } Context.Response.StatusCode = (int)HttpStatusCode.NoContent; }
public static List <Mapping> GetMappings(Site site, string path, string configPath = null) { HandlersSection section = HandlersHelper.GetHandlersSection(site, path, configPath); return(section.Mappings.ToList()); }