Exemplo n.º 1
0
        public async Task <HandleResult> CreateField(ModelField info)
        {
            var model = await _modelTableService.GetByNum(info.ModelNum);

            if (model == null)
            {
                return(HandleResult.Error("模型不存在"));
            }

            var tableName = $"CMS_U_{model.TableName}";

            var count = 0;

            switch (info.OptionType)
            {
            case ReactFormItemType.RangePicker:
                count += await GetDapper().CreateField($"{info.Name}Start", tableName, info.OptionType);

                count += await GetDapper().CreateField($"{info.Name}End", tableName, info.OptionType);

                break;

            default:
                count = await GetDapper().CreateField(info.Name, tableName, info.OptionType);

                break;
            }

            return(new HandleResult
            {
                IsSuccess = count > 0
            });
        }
Exemplo n.º 2
0
        public async Task <HandleResult> GetEdit([FromBody] JObject form)
        {
            var itemNum   = form["itemNum"].ToStr();
            var columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效数据"));
            }

            var column = await _columnService.GetByNum(columnNum);

            if (column == null)
            {
                return(HandleResult.Error("无效数据"));
            }

            var model = await _modelTableService.GetByNum(column.ModelNum);

            if (model == null)
            {
                return(HandleResult.Error("栏目未绑定模型"));
            }

            ContentData editValue = null;

            if (column.IsSingle)
            {
                editValue = await _service.GetFirstByColumnNum(model.SqlTableName, column.Num);
            }
            else
            {
                if (itemNum.IsEmpty())
                {
                    return(HandleResult.Error("无效数据"));
                }
                editValue = await _service.GetByItem(model.SqlTableName, itemNum);
            }

            return(new HandleResult
            {
                IsSuccess = true,
                Data = editValue.ToDictionary()
            });
        }
Exemplo n.º 3
0
        /// <summary>
        ///     获取栏目模型
        /// </summary>
        /// <param name="columnNum"></param>
        /// <returns></returns>
        public async Task <ColumnModel> GetModelByNum(string columnNum)
        {
            if (!_modelTables.ContainsKey(columnNum))
            {
                var column = await GetByNum(columnNum);

                if (column == null || column.ModelNum.IsEmpty())
                {
                    return(null);
                }

                var model = await _modelTableService.GetByNum(column.ModelNum);

                _modelTables[columnNum] = model;
                _columns[columnNum]     = column;
            }

            return(new ColumnModel
            {
                Column = _columns[columnNum],
                ModelTable = _modelTables[columnNum]
            });
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Tag(string num, string tag, int current = 1)
        {
            if (num.IsEmpty() || tag.IsEmpty())
            {
                return(Error404());
            }

            var site = _siteService.GetCurrentSite();

            if (site == null)
            {
                return(Error404());
            }

            var column = await _columnService.GetByNum(num);

            if (column == null || column.SiteNum != site.Num)
            {
                return(Error404());
            }

            var model = column.ModelNum.IsEmpty() ? null : await _modelTableService.GetByNum(column.ModelNum);

            string folderName = site.IsMobileSite ? site.MobileSiteFolder : site.SiteFolder;

            string templatePath = $"Views/Content/{folderName}/{column.ListTemplatePath}";

            if (!System.IO.File.Exists(Path.GetFullPath(templatePath)))
            {
                return(Error404());
            }

            int size = 15;

            switch (column.Num)
            {
            case "9a32d00252853c5e":
                size = 3;
                break;
            }

            var req = new SqlServerPageRequest
            {
                Current = current,
                Size    = size,
                Queries = new List <IQuery>
                {
                    new DefaultQuery(column.Num, new DefaultQuerySql("columnNum")),
                    new DefaultQuery(false, new DefaultQuerySql("IsDel")),
                    new DefaultQuery($"&|&|&{tag}&|&|&", new DefaultQuerySql("CONCAT('&|&|&', Tag, '&|&|&')", QuerySymbol.Like))
                }
            };

            var seo = new ContentSeo(column);

            if (model != null)
            {
                var rep = await _contentService.Page(model.SqlTableName, req);

                ViewData.Model = new ContentList
                {
                    Column     = column,
                    ModelTable = model,
                    Site       = site,
                    Data       = rep.Data.Select(temp => new ContentData(temp)),
                    PageConfig = new PageConfig
                    {
                        Current     = req.Current,
                        Size        = req.Size,
                        Total       = rep.Total,
                        UrlTemplate = "/tag/" + column.Num + "/" + tag + "/{p}"
                    }
                };
            }

            ViewBag.Seo  = seo;
            ViewBag.Site = site;
            ViewBag.Tag  = tag;
            return(View($"~/{templatePath}"));
        }
Exemplo n.º 5
0
        public async Task <HandleResult> Edit(JObject form, string accountNum)
        {
            var itemNum   = form["num"].ToStr();
            var columnNum = form["columnNum"].ToStr();

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error("无效的提交数据"));
            }

            var column = await _columnService.GetByNum(columnNum);

            if (column == null)
            {
                return(HandleResult.Error("无效的提交数据"));
            }

            var model = await _modelTableService.GetByNum(column.ModelNum);

            if (model == null)
            {
                return(HandleResult.Error("栏目未绑定模型"));
            }

            ContentData oldData = null;

            if (column.IsSingle)
            {
                oldData = await GetFirstByColumnNum(model.SqlTableName, column.Num);
            }
            else if (itemNum.IsNotEmpty())
            {
                oldData = await GetByItem(model.SqlTableName, itemNum);
            }

            var id = oldData?.Id ?? 0;

            var contentEdit = new DynamicTableSqlHelper(model.SqlTableName);

            contentEdit.SetData(await _columnFieldService.GetByColumnNum(columnNum), form);
            contentEdit.AddFieldAndValue("SeoTitle", form["seoTitle"].ToStr());
            contentEdit.AddFieldAndValue("SeoKeyword", form["seoKeyword"].ToStr());
            contentEdit.AddFieldAndValue("SeoDesc", form["seoDesc"].ToStr());
            contentEdit.AddFieldAndValue("CategoryNum", form["categoryNum"].ToStr());
            contentEdit.AddFieldAndValue("IsTop", form["isTop"].ToBoolean());

            if (id > 0)
            {
                contentEdit.AddFieldAndValue("UpdateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("UpdateDate", DateTime.Now);
            }
            else
            {
                contentEdit.AddFieldAndValue("Num", RandomHelper.CreateNum());
                contentEdit.AddFieldAndValue("CreateDate", DateTime.Now);
                contentEdit.AddFieldAndValue("UpdateDate", DateTime.Now);
                contentEdit.AddFieldAndValue("CreateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("UpdateAccountNum", accountNum);
                contentEdit.AddFieldAndValue("IsDel", false);
                contentEdit.AddFieldAndValue("Status", 0);
                contentEdit.AddFieldAndValue("SiteNum", column.SiteNum);
                contentEdit.AddFieldAndValue("ColumnNum", columnNum);
            }

            return(id > 0 ? await Update(contentEdit, id) : await Add(contentEdit));
        }