public object Get(string id)
        {
            var mimeMapId = new MimeMapId(id);

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

            List <MimeMap> mimeMaps = MimeMapHelper.GetMimeMaps(site, mimeMapId.Path);

            MimeMap mimeMap = mimeMaps.FirstOrDefault(m => m.FileExtension.Equals(mimeMapId.FileExtension));

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

            return(MimeMapHelper.ToJsonModel(mimeMap, site, mimeMapId.Path));
        }
        public object Post([FromBody] dynamic model)
        {
            if (model == null)
            {
                throw new ApiArgumentException("model");
            }
            if (model.static_content == null)
            {
                throw new ApiArgumentException("static_content");
            }
            if (!(model.static_content is JObject))
            {
                throw new ApiArgumentException("static_content");
            }
            string staticContentUuid = DynamicHelper.Value(model.static_content.id);

            if (staticContentUuid == null)
            {
                throw new ApiArgumentException("static_content.id");
            }

            // Get the feature id
            StaticContentId staticContentId = new StaticContentId(staticContentUuid);

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

            string configPath            = ManagementUnit.ResolveConfigScope(model);
            StaticContentSection section = StaticContentHelper.GetSection(site, staticContentId.Path, configPath);

            // Create mime map
            MimeMap mimeMap = MimeMapHelper.CreateMimeMap(model, section);

            // Add it to the config file
            MimeMapHelper.AddMimeMap(mimeMap, section);

            // Save changes
            ManagementUnit.Current.Commit();


            // Show new mime map
            return(MimeMapHelper.ToJsonModel(mimeMap, site, staticContentId.Path));
        }
        public object Patch(string id, [FromBody] dynamic model)
        {
            var mimeMapId = new MimeMapId(id);

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

            string         configPath = model == null ? null : ManagementUnit.ResolveConfigScope(model);
            List <MimeMap> mimeMaps   = MimeMapHelper.GetMimeMaps(site, mimeMapId.Path, configPath);

            MimeMap mimeMap = mimeMaps.FirstOrDefault(m => m.FileExtension.Equals(mimeMapId.FileExtension));

            if (mimeMap == null)
            {
                return(new NotFoundResult());
            }

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

            var section = StaticContentHelper.GetSection(site, mimeMapId.Path, configPath);

            MimeMapHelper.UpdateMimeMap(model, mimeMap, section);

            ManagementUnit.Current.Commit();

            dynamic mm = MimeMapHelper.ToJsonModel(mimeMap, site, mimeMapId.Path);

            if (mm.id != id)
            {
                return(LocationChanged(MimeMapHelper.GetLocation(mm.id), mm));
            }

            return(mm);
        }