public void Delete(string id)
        {
            var mimeMapId = new MimeMapId(id);

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

            if (mimeMapId.SiteId != null && site == null)
            {
                Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
                return;
            }

            MimeMap mimeMap = MimeMapHelper.GetMimeMaps(site, mimeMapId.Path).FirstOrDefault(m => m.FileExtension.Equals(mimeMapId.FileExtension));

            if (mimeMap != null)
            {
                var section = StaticContentHelper.GetSection(site, mimeMapId.Path, ManagementUnit.ResolveConfigScope());

                MimeMapHelper.DeleteMimeType(mimeMap, section);
                ManagementUnit.Current.Commit();
            }


            Context.Response.StatusCode = (int)HttpStatusCode.NoContent;
        }
        public object Get()
        {
            string staticContentUuid = Context.Request.Query[Defines.IDENTIFIER];

            if (string.IsNullOrEmpty(staticContentUuid))
            {
                return(NotFound());
            }

            StaticContentId id = new StaticContentId(staticContentUuid);

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

            List <MimeMap> mappings = MimeMapHelper.GetMimeMaps(site, id.Path);

            // Set HTTP header for total count
            this.Context.Response.SetItemsCount(mappings.Count());

            Fields fields = Context.Request.GetFields();

            return(new
            {
                mime_maps = mappings.Select(m => MimeMapHelper.ToJsonModelRef(m, site, id.Path, fields))
            });
        }
        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 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);
        }