Beispiel #1
0
        public ActionResult Create(int listId)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var list = listService.GetById(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(T("Create"));

            var model = new ListCategoryModel
            {
                ListId = listId
            };

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

            var dataSource = listCategoryService.GetCategories(listId).Select(x => new { Key = x.Id.ToString(), Value = FormatCategoryText(x.Name, x.ParentId, listCategoryService.GetCategories(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);
        }
Beispiel #2
0
        public IList <ListItem> GetListItemsByCategoryId(int listId, int categoryId, string ordering, int pageIndex, int pageSize, out int totals)
        {
            var categories      = listCategoryService.GetCategories(listId);
            var childCategories = new List <int>();

            GetChildCategories(categoryId, categories, childCategories);
            childCategories.Insert(0, categoryId);

            var predicate = PredicateBuilder.False <ListItemCategory>();

            predicate = childCategories.Aggregate(predicate, (current, seed) => current.Or(x => x.CategoryId == seed));

            var query = from item in Repository.Table
                        join itemCategory in Repository.GetTable <ListItemCategory>().AsExpandable().Where(predicate)
                        on item.Id equals itemCategory.ItemId
                        select item;

            totals = query.Count();

            if (string.IsNullOrEmpty(ordering))
            {
                var items = query
                            .OrderBy(x => x.Position)
                            .Skip((pageIndex - 1) * pageSize)
                            .Take(pageSize)
                            .ToList();

                return(items);
            }
            else
            {
                var items = query
                            .OrderBy(ordering)
                            .Skip((pageIndex - 1) * pageSize)
                            .Take(pageSize)
                            .ToList();

                return(items);
            }
        }
Beispiel #3
0
        public ActionResult Create(int listId)
        {
            if (!CheckPermission(ListsPermissions.ManageLists))
            {
                return(new HttpUnauthorizedResult());
            }

            var list = listService.GetById(listId);

            var result = new ControlFormResult
            {
                Title            = T("Create List Item").Text,
                UpdateActionName = "Update",
                CssClass         = "form-edit-list-item",
            };

            result.AddProperty("Id", new ControlHiddenAttribute(), 0);
            result.AddProperty("ListId", new ControlHiddenAttribute(), listId);
            result.AddProperty("Title", new ControlTextAttribute
            {
                Required          = true,
                MaxLength         = 255,
                LabelText         = "Title",
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, string.Empty);

            result.AddProperty("Slug", new ControlSlugAttribute
            {
                MaxLength         = 255,
                HelpText          = string.Format(T("List item url will become {0}/{{slug}}").Text, list.Url),
                LabelText         = "Slug",
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 0
            }, string.Empty);

            result.AddProperty("PictureUrl", new ControlFileUploadAttribute
            {
                EnableFineUploader = true,
                LabelText          = "Picture Url",
                UploadFolder       = list.Name,
                ContainerCssClass  = "col-md-6",
                ContainerRowIndex  = 1
            }, string.Empty);

            var categories     = listCategoryService.GetCategories(listId);
            var selectList     = new List <SelectListItem>();
            var rootCategories = categories.Where(x => x.ParentId == null).OrderBy(x => x.Position).ThenBy(x => x.Name);

            GetCategoriesSelectList(rootCategories, selectList, categories, "");

            result.AddProperty("Categories", new ControlChoiceAttribute(ControlChoice.DropDownList)
            {
                LabelText         = "Categories",
                SelectListItems   = selectList,
                PropertyType      = typeof(string),
                EnableChosen      = true,
                AllowMultiple     = true,
                ContainerCssClass = "col-md-6",
                ContainerRowIndex = 1
            }, new Guid[] { });

            if (list.EnabledMetaTags)
            {
                result.AddProperty("MetaKeywords", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Keywords",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, string.Empty);

                result.AddProperty("MetaDescription", new ControlTextAttribute
                {
                    MaxLength         = 255,
                    LabelText         = "Meta Description",
                    ContainerCssClass = "col-md-6",
                    ContainerRowIndex = 2
                }, string.Empty);
            }

            result.AddProperty("Position", new ControlNumericAttribute
            {
                Required          = true,
                PropertyType      = typeof(int),
                LabelText         = "Position",
                ContainerCssClass = "col-md-1",
                ContainerRowIndex = 3
            }, 0);

            result.AddProperty("Enabled", new ControlChoiceAttribute(ControlChoice.CheckBox)
            {
                PropertyType      = typeof(bool),
                LabelText         = "",
                AppendText        = "Enabled",
                ContainerCssClass = "col-md-2",
                ContainerRowIndex = 3
            }, true);

            var fields = listFieldService.GetFields(listId);

            foreach (var field in fields)
            {
                field.BindControlField(result, string.Empty);
            }

            return(result);
        }