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 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);
        }