Exemplo n.º 1
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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        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;
        }