예제 #1
0
        public object Post([FromBody] dynamic model)
        {
            Extension extension = null;
            Site      site      = null;

            RequestFilteringId reqId = null;

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            if (model.request_filtering == null)
            {
                throw new ApiArgumentException("request_filtering");
            }
            if (!(model.request_filtering is JObject))
            {
                throw new ApiArgumentException(String.Empty, "request_filtering");
            }
            string reqUuid = DynamicHelper.Value(model.request_filtering.id);

            if (reqUuid == null)
            {
                throw new ApiArgumentException("request_filtering.id");
            }

            // Get the feature id
            reqId = new RequestFilteringId(reqUuid);

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

            string configPath = ManagementUnit.ResolveConfigScope(model);
            RequestFilteringSection section = RequestFilteringHelper.GetRequestFilteringSection(site, reqId.Path, configPath);

            extension = ExtensionsHelper.CreateExtension(model, section);

            ExtensionsHelper.AddExtension(extension, section);

            ManagementUnit.Current.Commit();

            //
            // Create response
            dynamic ext = ExtensionsHelper.ToJsonModel(extension, site, reqId.Path);

            return(Created(ExtensionsHelper.GetLocation(ext.id), ext));
        }
예제 #2
0
        public object Patch(string id, [FromBody] dynamic model)
        {
            ExtensionId extId = new ExtensionId(id);

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

            if (extId.SiteId != null && site == null)
            {
                return(new StatusCodeResult((int)HttpStatusCode.NotFound));
            }

            if (model == null)
            {
                throw new ApiArgumentException("model");
            }

            string    configPath = ManagementUnit.ResolveConfigScope(model);
            Extension extension  = ExtensionsHelper.GetExtensions(site, extId.Path, configPath).
                                   FirstOrDefault(e => e.FileExtension.ToString().Equals(extId.FileExtension));

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

            extension = ExtensionsHelper.UpdateExtension(extension, model);

            ManagementUnit.Current.Commit();

            dynamic ext = ExtensionsHelper.ToJsonModel(extension, site, extId.Path);

            if (ext.id != id)
            {
                return(LocationChanged(ExtensionsHelper.GetLocation(ext.id), ext));
            }

            return(ext);
        }
        private void ConfigureFileExtensions()
        {
            Environment.Host.RouteBuilder.MapWebApiRoute(Defines.FileExtensionsResource.Guid, $"{ Defines.FILE_NAME_EXTENSIONS_PATH}/{{id?}}", new { controller = "filenameextensions" });

            Environment.Hal.ProvideLink(Defines.FileExtensionsResource.Guid, "self", fn => new { href = ExtensionsHelper.GetLocation(fn.id) });

            Environment.Hal.ProvideLink(Defines.Resource.Guid, Defines.FileExtensionsResource.Name, rf => new { href = $"/{Defines.FILE_NAME_EXTENSIONS_PATH}?{Defines.IDENTIFIER}={rf.id}" });
        }