示例#1
0
        public ActionResult Update(Guid id, LanguageType langType, string viewName = "_Edit")
        {
            var         dataModel     = service.GetView(id, langType);
            var         model         = new EditItemViewModel(dataModel);
            List <Guid> topStructures = new List <Guid>();
            cms_Item    parentItem    = null;

            if (viewName == "_Edit") //一般
            {
                topStructures = structureService.GetTopParents(model.Item.StructureID);
            }
            else //項目
            {
                parentItem = service.Get(model.ParentID);
            }

            model.CategoryTree = service.GetTrees(parentItem, new ItemTreeFilter
            {
                ItemType           = ItemType.Category,
                TopStructures      = topStructures,
                EndWithStructureID = model.Item.StructureID,
                CheckIDs           = model.ParentItems?.Select(x => x.ID).ToList(),
                LangType           = (LanguageType)model.Item.cms_Structure.DefaultLanguage
            });
            model.SelectList = service.GetArticleGroup(model.Item.cms_Structure, (LanguageType)model.Item.cms_Structure.DefaultLanguage, model.ParentID);

            model.AllowRoleCheckList   = service.GetOrderRoleCheckList(id, ItemOrderRoleType.OrderAllowRole);
            model.CreateRoleSelectList = service.GetOrderRoleCheckList(id, ItemOrderRoleType.OrderCreateRole);
            model.DepartmentSelectList = departmentService.GetSelectList(SessionManager.DepartmentID, selectedID: model.Item.DepartmentID);

            //語系可null
            if (model.ItemLanguage == null)
            {
                model.ItemLanguage = new cms_ItemLanguage {
                    LanguageType = (int)langType
                };
            }
            else
            {
                // Html Decode
                model.ItemLanguage.Content      = HttpUtility.HtmlDecode(model.ItemLanguage.Content);
                model.ItemLanguage.TemplateText = HttpUtility.HtmlDecode(model.ItemLanguage.TemplateText);
            }
            // Html Decode
            model.Item.cms_Structure.Template = HttpUtility.HtmlDecode(model.Item.cms_Structure.Template);

            return(PartialView(viewName, model));
        }
示例#2
0
        public ActionResult Create(Guid structureIDs, Guid?parentID = null, string viewName = "_Edit")
        {
            cms_Structure structure     = structureService.Get(structureIDs);
            List <Guid>   topStructures = new List <Guid>();
            cms_Item      parentItem    = null;

            if (viewName == "_Edit") //一般
            {
                topStructures = structureService.GetTopParents(structureIDs);
            }
            else //項目
            {
                parentItem = service.Get(parentID.Value);
            }


            var model = new EditItemViewModel
            {
                Item = new cms_Item
                {
                    StructureID   = structure.ID,
                    cms_Structure = structure
                },
                ItemLanguage = new cms_ItemLanguage {
                    LanguageType = structure.DefaultLanguage
                },
                CategoryTree = service.GetTrees(parentItem, new ItemTreeFilter
                {
                    ItemType           = ItemType.Category,
                    TopStructures      = topStructures,
                    EndWithStructureID = structure.ID,
                    LangType           = (LanguageType)structure.DefaultLanguage,
                }),
                SelectList           = service.GetArticleGroup(structure, (LanguageType)structure.DefaultLanguage),
                AllowRoleCheckList   = service.GetOrderRoleCheckList(null, ItemOrderRoleType.OrderAllowRole),
                CreateRoleSelectList = service.GetOrderRoleCheckList(null, ItemOrderRoleType.OrderCreateRole),
                DepartmentSelectList = departmentService.GetSelectList(SessionManager.DepartmentID)
            };

            // parent
            if (parentID != null)
            {
                model.ParentID = parentID.Value;
            }

            // routename random (no edit)
            if (!structure.ContentTypes.HasValue((int)ContentType.RouteName))
            {
                model.Item.RouteName = Guid.NewGuid().ToString();
            }

            // get sort
            if (structure.ContentTypes.HasValue((int)ContentType.Sort))
            {
                model.Item.Sort = service.GetSort(structureIDs) + 1;

                if (viewName == "_OptionEdit")
                {
                    model.Item.Sort *= -1; //新的在最下方
                }
            }

            // people range defalut:1
            if (structure.ContentTypes.HasValue((int)ContentType.PeopleRange))
            {
                model.Item.PeopleMin = 1;
                model.Item.PeopleMax = 1;
            }

            // Html Decode
            model.Item.cms_Structure.Template = HttpUtility.HtmlDecode(model.Item.cms_Structure.Template);

            return(PartialView(viewName, model));
        }