Example #1
0
        /// <summary>
        /// 内容类别添加
        /// </summary>
        /// <returns></returns>
        public ActionResult AddContentType()
        {
            ContentTypeInput model = new ContentTypeInput();

            ViewData["Define"] = _defineAppService.GetDefine();
            model.IsEdit       = false;
            return(View("Easyman.FwWeb.Views.Content.AddContentType", model));
        }
Example #2
0
        /// <summary>
        /// 内容类别新增或修改
        /// </summary>
        /// <param name="input"></param>
        public void UpdateOrInserContentType(ContentTypeInput input)
        {
            var type = _contentTypeRepository.GetAll().FirstOrDefault(a => a.Id == input.Id) ?? new ContentType();
            // var temp = _contentTypeRepository.GetAll().FirstOrDefault(a => a.Id == input.ParentId);
            var typeCount = _contentTypeRepository.GetAll().Count(a => a.Name == input.Name);

            if (input.DefineId == 0)
            {
                throw new UserFriendlyException("请选择内容定义");
            }
            //if (typeCount >= 1 && input.Id == 0)
            //    throw new UserFriendlyException("内容类别名称已存在");
            //if (typeCount >= 2 && input.Id != 0)
            //    throw new UserFriendlyException("内容类别名称已存在");
            if (_contentTypeRepository.GetAll().Any(p => p.Id != input.Id && p.Name == input.Name))
            {
                throw new UserFriendlyException("名为【" + input.Name + "】的对象已存在!");
            }
            type.DefineId     = input.DefineId;
            type.CreationTime = DateTime.Now;
            type.Name         = input.Name;
            if (input.Id == 0)
            {
                if (input.ParentId != 0)//新增
                {
                    type.ParentId = input.ParentId;
                }
            }
            else
            {
                var state  = false;
                var result = _contentTypeRepository.GetAll().Where(a => a.ParentId == input.Id);
                foreach (var item in result)
                {
                    if (item.Id == input.ParentId)
                    {
                        state = true;
                    }
                }
                if (!state && input.Id != input.ParentId)
                {
                    type.ParentId = input.ParentId;
                }
                else
                {
                    throw new UserFriendlyException("保存失败,不能嵌套循环!上级不能选择自身!");
                }
                //if (temp != null && (input.ParentId != type.ParentId && temp.Id != type.Id))//编辑
                //    type.ParentId = input.ParentId;
                //else if (temp == null)
                //{
                //    type.ParentId = input.ParentId;
                //}
            }
            type.ShowOrder = input.ShowOrder;
            _contentTypeRepository.InsertOrUpdate(type);
        }