Ejemplo n.º 1
0
        public static IEnumerable <Breadcrumb> GetBreadcrumbsList <TModel>(this WebViewPage <TModel> page)
            where TModel : class
        {
            var crumbs = new List <Breadcrumb>();

            // Begin breadcrumbs with home
            crumbs.Add(
                new Breadcrumb(
                    StringHelper.SplitCamelCase(MvcBootstrapConfig.HomeControllerName),
                    page.Url.Action(HomeControllerAction.Index, MvcBootstrapConfig.HomeControllerName)));

            var    controller     = page.Controller();
            string controllerName = controller.Name();
            string actionName     = page.ActionName();

            if (controller.IsHomeController())
            {
                // Only actions other than Index get a breadcrumb
                if (actionName != HomeControllerAction.Index)
                {
                    crumbs.Add(
                        new Breadcrumb(
                            StringHelper.SplitCamelCase(actionName),
                            page.Url.Action(actionName, MvcBootstrapConfig.HomeControllerName)));
                }
            }
            else
            {
                // Controllers other than home get their own breadcrumb
                crumbs.Add(new Breadcrumb(controller.Name(), page.Url.Action(BootstrapActionName.List, controllerName)));

                if (controller.IsBootstrapController())
                {
                    // Bootstrap controllers have specific rules for their CRUD actions
                    switch (page.ActionName())
                    {
                    case BootstrapActionName.List:
                        // The list action is represented by the controller name breadcrumb, already added.
                        break;

                    case BootstrapActionName.Create:
                        // The create action is represented by an additional breadcrumb on the controller
                        crumbs.Add(
                            new Breadcrumb(
                                BootstrapActionName.Create,
                                page.Url.Action(BootstrapActionName.Create, controllerName)));
                        break;

                    case BootstrapActionName.Read:
                    {
                        var viewModel = (IEntityViewModel)page.Model;
                        // The read action is represented by the model's label
                        crumbs.Add(
                            new Breadcrumb(
                                page.GetModelLabel(),
                                page.Url.Action(BootstrapActionName.Read, controllerName, new { viewModel.Id })));
                    }
                    break;

                    case BootstrapActionName.Update:
                    {
                        var viewModel = (IEntityViewModel)page.Model;
                        // The Update action gets two breadcrumbs: the model's label...
                        crumbs.Add(
                            new Breadcrumb(
                                page.GetModelLabel(),
                                page.Url.Action(BootstrapActionName.Read, controllerName, new { viewModel.Id })));
                        // ... and "Update"
                        crumbs.Add(
                            new Breadcrumb(
                                BootstrapActionName.Update,
                                page.Url.Action(BootstrapActionName.Update, controllerName)));
                    }
                    break;

                    case BootstrapActionName.Delete:
                    {
                        var viewModel = (IEntityViewModel)page.Model;
                        // The Delete action gets two breadcrumbs: the model's label...
                        crumbs.Add(
                            new Breadcrumb(
                                page.GetModelLabel(),
                                page.Url.Action(
                                    BootstrapActionName.Read, controllerName, new { viewModel.Id })));
                        // ... and "Delete"
                        crumbs.Add(
                            new Breadcrumb(
                                BootstrapActionName.Delete,
                                page.Url.Action(BootstrapActionName.Delete, controllerName)));
                    }
                    break;
                    }
                }
                else
                {
                    // Controllers that are neither Home nor Bootstrap just add their action
                    crumbs.Add(new Breadcrumb(actionName, page.Url.Action(actionName, controllerName)));
                }
            }

            return(crumbs);
        }