public void MapRoute(ResourceData resource)
 {
     resource.Collection.ForEach(c => Index(resource, c));
     resource.Member.ForEach(m => Show(resource, m));
     
     Index(resource);
     Show(resource);
     New(resource);
     Create(resource);
     Edit(resource);
     Update(resource);
     Destroy(resource);
 }
示例#2
0
        public static ResourceData Build(Resource builder, bool shallow = false)
        {
            var data = new ResourceData()
            {
                Name = builder.Name,
                Scope = builder.Scope,
                Collection = GetActions(builder, ResourceMemberType.Collection),
                Member = GetActions(builder, ResourceMemberType.Member),
                Except = GetExceptions(builder)
            };

            if (builder.Parent != null)
            {
                data.Parent = Build(builder.Parent, true);
            }

            if (!shallow)
            {
                data.Nested = GetNested(builder);
            }

            return data;
        }
 private void Map(ResourceData resource, ResourceMethod method, string url, string on = "", HttpVerbs verb = HttpVerbs.Get)
 {
     this.Routes.MapRoute(resource.RouteName(method, on), url,
         new { controller = resource.Name, action = method.ToString().ToLowerInvariant() });
 }
 private void Destroy(ResourceData resource, string member = "")
 {
     Map(resource, ResourceMethod.Destroy, resource.ItemUrl(member), member, HttpVerbs.Delete);
 }
 private void Update(ResourceData resource, string member = "")
 {
     Map(resource, ResourceMethod.Update, resource.ItemUrl(member), member, HttpVerbs.Put);
 }
 private void Edit(ResourceData resource, string member = "")
 {
     Map(resource, ResourceMethod.Edit, resource.ItemUrl(member) + "/edit/", member);
 }
        private void Create(ResourceData resource, string member = "")
        {
            string url = member.IsNullOrEmpty() ? resource.BaseUrl() : resource.ItemUrl(member);

            Map(resource, ResourceMethod.Create, url, member, HttpVerbs.Post);
        }
 private void New(ResourceData resource, string member = "")
 {
     Map(resource, ResourceMethod.New, resource.ItemUrl(member) + "new/", member);
 }
 private void Show(ResourceData resource, string member = "")
 {
     Map(resource, ResourceMethod.Show, resource.ItemUrl(member), member);
 }
 private void Index(ResourceData resource, string collection = "")
 {
     Map(resource, ResourceMethod.Index, resource.BaseUrl(collection), collection);
 }
        protected void AddResource(ResourceData resource)
        {
            this.ResourceRouteGenerator.MapRoute(resource);

            resource.Nested.ForEach(nested => AddResource(nested));
        }