Esempio n. 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("操作失败"));
        }
Esempio n. 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("操作失败"));
        }