public object Patch([FromBody] dynamic model, string id) { var rewriteMapId = new RewriteMapId(id); Site site = rewriteMapId.SiteId == null ? null : SiteHelper.GetSite(rewriteMapId.SiteId.Value); if (rewriteMapId.SiteId != null && site == null) { return(NotFound()); } RewriteMapsSection section = RewriteMapsHelper.GetSection(site, rewriteMapId.Path); RewriteMap map = section.RewriteMaps.FirstOrDefault(r => r.Name.Equals(rewriteMapId.Name, StringComparison.OrdinalIgnoreCase)); if (map == null) { return(NotFound()); } RewriteMapsHelper.UpdateMap(model, map, section); ManagementUnit.Current.Commit(); dynamic updatedMap = RewriteMapsHelper.MapToJsonModel(map, site, rewriteMapId.Path, Context.Request.GetFields(), true); if (updatedMap.id != id) { return(LocationChanged(RewriteMapsHelper.GetMapLocation(updatedMap.id), updatedMap)); } return(updatedMap); }
public object Post([FromBody] dynamic model) { if (model == null) { throw new ApiArgumentException("model"); } RewriteId parentId = RewriteHelper.GetRewriteIdFromBody(model); if (parentId == null) { throw new ApiArgumentException("url_rewrite"); } Site site = parentId.SiteId == null ? null : SiteHelper.GetSite(parentId.SiteId.Value); string configPath = ManagementUnit.ResolveConfigScope(model); RewriteMapsSection section = RewriteMapsHelper.GetSection(site, parentId.Path, configPath); RewriteMap map = RewriteMapsHelper.CreateMap(model, section); RewriteMapsHelper.AddMap(map, section); ManagementUnit.Current.Commit(); dynamic r = RewriteMapsHelper.MapToJsonModel(map, site, parentId.Path, Context.Request.GetFields(), true); return(Created(RewriteMapsHelper.GetMapLocation(r.id), r)); }
private void ConfigureRewriteMaps() { var builder = Environment.Host.RouteBuilder; var hal = Environment.Hal; builder.MapWebApiRoute(Defines.RewriteMapsSectionResource.Guid, $"{Defines.REWRITE_MAPS_SECTION_PATH}/{{id?}}", new { controller = "RewriteMapsSection" }); builder.MapWebApiRoute(Defines.RewriteMapsResource.Guid, $"{Defines.REWRITE_MAPS_PATH}/{{id?}}", new { controller = "RewriteMaps" }); // () -> Self hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, "self", sv => new { href = RewriteMapsHelper.GetSectionLocation(sv.id) }); hal.ProvideLink(Defines.RewriteMapsResource.Guid, "self", ir => new { href = RewriteMapsHelper.GetMapLocation(ir.id) }); // Rewrite -> Section hal.ProvideLink(Defines.Resource.Guid, Defines.RewriteMapsSectionResource.Name, rewrite => new { href = RewriteMapsHelper.GetSectionLocation(rewrite.id) }); // Section -> Maps hal.ProvideLink(Defines.RewriteMapsSectionResource.Guid, Defines.RewriteMapsResource.Name, section => new { href = $"/{Defines.REWRITE_MAPS_PATH}?{Defines.IDENTIFIER}={section.id}" }); }