Beispiel #1
0
        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));
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        public object Get(string id)
        {
            MappingId mappingId = new MappingId(id);

            Site site = mappingId.SiteId == null ? null : SiteHelper.GetSite(mappingId.SiteId.Value);

            if (mappingId.SiteId != null && site == null)
            {
                return(NotFound());
            }

            Mapping mapping = MappingsHelper.GetMappings(site, mappingId.Path).FirstOrDefault(u => u.Name.Equals(mappingId.Name));

            if (mapping == null)
            {
                return(NotFound());
            }

            return(MappingsHelper.ToJsonModel(mapping, site, mappingId.Path));
        }