Exemple #1
0
        public ActionResult Edit(int id)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var model = listCategoryService.GetById(id);
            var list  = listService.GetById(model.ListId);

            WorkContext.Breadcrumbs.Add(T("Manage Lists"), Url.Action("Index", "List", new { area = Constants.Areas.Lists }));
            WorkContext.Breadcrumbs.Add(list.Name);
            WorkContext.Breadcrumbs.Add(T("Categories"), Url.Action("Index", new { area = Constants.Areas.Lists }));
            WorkContext.Breadcrumbs.Add(model.Name);
            WorkContext.Breadcrumbs.Add(T("Edit"));

            var result = new ControlFormResult <ListCategoryModel>(model)
            {
                Title                = T("Edit Category").Text,
                UpdateActionName     = "Update",
                ShowBoxHeader        = false,
                FormWrapperStartHtml = Constants.Form.FormWrapperStartHtml,
                FormWrapperEndHtml   = Constants.Form.FormWrapperEndHtml
            };

            var dataSource = listCategoryService.GetCategories(model.ListId).Where(x => x.Id != id).Select(x => new { Key = x.Id.ToString(), Value = FormatCategoryText(x.Name, x.ParentId, listCategoryService.GetCategories(model.ListId), "\xA0\xA0\xA0\xA0\xA0") }).ToList();

            dataSource.Insert(0, new { Key = "", Value = "" });
            result.RegisterExternalDataSource(x => x.ParentId, dataSource.ToDictionary(x => x.Key, x => x.Value));

            return(result);
        }
        public ActionResult Category(int listId, string pathInfo)
        {
            var    segments  = pathInfo.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            var    pageIndex = 1;
            string slug;

            if (segments.Length > 1)
            {
                if (int.TryParse(segments[segments.Length - 1], out pageIndex))
                {
                    slug = string.Join("/", segments, 0, segments.Length - 1);
                }
                else
                {
                    slug      = string.Join("/", segments);
                    pageIndex = 1;
                }
            }
            else
            {
                slug = segments[0];
            }

            int categoryId;

            if (listCategoryPathConstraint.Match(listId, slug, out categoryId))
            {
                var category = listCategoryService.GetById(categoryId);
                if (category == null)
                {
                    return(new HttpNotFoundResult());
                }

                var list = listService.GetById(category.ListId);
                if (list == null)
                {
                    return(new HttpNotFoundResult());
                }

                int totals;
                var items = listItemService.GetListItemsByCategoryId(listId, categoryId, list.Sorting, pageIndex, list.PageSize, out totals);

                var sb = new StringBuilder();

                if (!string.IsNullOrEmpty(list.CssClass))
                {
                    sb.AppendFormat("<div class=\"{0}\">", list.CssClass);
                }

                if (items.Count > 0 && !string.IsNullOrEmpty(list.SummaryTemplate))
                {
                    var fields = listFieldService.GetFields(list.Id);
                    TemplateHelper.BuildContent(list, fields, items, list.SummaryTemplate, sb, Url);
                }

                if (totals > 0)
                {
                    TemplateHelper.BuildPagination(sb, Url, RouteData.Values, totals, pageIndex, list.PageSize);
                }

                if (!string.IsNullOrEmpty(list.CssClass))
                {
                    sb.Append("</div>");
                }

                return(new ControlContentResult(sb.ToString())
                {
                    Title = list.Name + " - " + category.Name
                });
            }

            return(Item(listId, slug));
        }