示例#1
0
        public async Task <HandleResult> Edit(JObject form, string accountNum)
        {
            var num       = form["num"].ToStr();
            var columnNum = form["columnNum"].ToStr();

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

            var cm = await _columnService.GetModelByNum(columnNum);

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

            var column = cm?.Column;
            var model  = cm?.ModelTable;

            var oldData = num.IsEmpty() ? null : await _dapper.GetByNum(model.SqlCategoryTableName, num);

            var id        = oldData?.Id ?? 0;
            var parentNum = form["parentNum"].ToStr();

            if (oldData != null && oldData.Num == parentNum)
            {
                return(HandleResult.Error("父类别不能是自身"));
            }

            var contentEdit = new DynamicTableSqlHelper(model.SqlCategoryTableName);

            contentEdit.AddFieldAndValue("Name", form["name"].ToStr());
            contentEdit.AddFieldAndValue("ParentNum", parentNum);

            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);
            }

            var sql = id > 0 ? contentEdit.GetUpdateSql(id) : contentEdit.GetAddSql();
            var res = await _dapper.Execute(sql, contentEdit.GetValue());

            return(res > 0 ? HandleResult.Success() : HandleResult.Error("操作失败"));
        }
示例#2
0
        public async Task <HandleResult> Add(DynamicTableSqlHelper form)
        {
            var sql = form.GetAddSql();

            if (sql.IsEmpty())
            {
                return(HandleResult.Error());
            }

            var res = await _dapper.Execute(sql, form.GetValue());

            return(res > 0 ? HandleResult.Success() : HandleResult.Error("操作失败"));
        }
示例#3
0
        public Task <HandleResult> Update(Dictionary <string, object> form, string tableName)
        {
            if (!form.ContainsKey("id"))
            {
                return(Task.FromResult(HandleResult.Error()));
            }

            var id = form["id"].ToInt();

            if (id <= 0)
            {
                return(Task.FromResult(HandleResult.Error()));
            }

            var sqlHelper = new DynamicTableSqlHelper(tableName);

            sqlHelper.SetDictionaryData(form, new[] { "id" });

            return(Update(sqlHelper, id));
        }
示例#4
0
        public async Task <HandleResult> Submit(IFormCollection form)
        {
            string columnNum = form["columnNum"];

            if (columnNum.IsEmpty())
            {
                return(HandleResult.Error());
            }

            var columnModel = await _columnService.GetModelByNum(columnNum);

            if (columnModel?.ModelTable == null)
            {
                return(HandleResult.Error());
            }

            var fields = await _columnFieldService.GetByColumnNum(columnNum);

            var columnFields = fields as ColumnField[] ?? fields.ToArray();

            var edit = ContentData.CreateEmptyInstance(columnModel.Column.SiteNum, columnModel.Column.Num);

            foreach (var field in columnFields)
            {
                if (form.ContainsKey(field.Name))
                {
                    edit[field.Name] = form[field.Name];
                }
            }

            var tableSqlHelper = new DynamicTableSqlHelper(columnModel.ModelTable.SqlTableName);

            tableSqlHelper.SetContentData(columnFields, edit);

            return(await _contentService.Add(tableSqlHelper));
        }
示例#5
0
        public async Task <HandleResult> UpdateSeo([FromBody] JObject form)
        {
            var data = new ContentData(form);

            if (data.Id <= 0 || data.ColumnNum.IsEmpty())
            {
                return(HandleResult.Error());
            }

            var cm = await _columnService.GetModelByNum(data.ColumnNum);

            if (cm == null || cm.Column == null || cm.ModelTable == null)
            {
                return(HandleResult.Error());
            }

            var tableSql = new DynamicTableSqlHelper(cm.ModelTable.SqlTableName);

            tableSql.AddFieldAndValue("SeoTitle", data.SeoTitle);
            tableSql.AddFieldAndValue("SeoKeyword", data.SeoKeyword);
            tableSql.AddFieldAndValue("SeoDesc", data.SeoDesc);

            return(await _service.Update(tableSql, data.Id));
        }
示例#6
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));
        }