Exemple #1
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysCode parm)
        {
            var res = new ApiResult <string>()
            {
                statusCode = 200
            };

            try
            {
                //判断是否存在
                var isExt = SysCodeDb.IsAny(m => m.Name == parm.Name && m.ParentGuid == parm.ParentGuid);
                if (isExt)
                {
                    res.statusCode = (int)ApiEnum.ParameterError;
                    res.message    = "该名称已存在~";
                }
                else
                {
                    parm.Guid = Guid.NewGuid().ToString();
                    var dbres = SysCodeDb.Insert(parm);
                    if (!dbres)
                    {
                        res.statusCode = (int)ApiEnum.Error;
                        res.message    = "插入数据失败~";
                    }
                }
            }
            catch (Exception ex)
            {
                res.statusCode = (int)ApiEnum.Error;
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(await Task.Run(() => res));
        }
Exemple #2
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysCode parm)
        {
            var dbres = SysCodeDb.Insert(parm);
            var res   = new ApiResult <string>
            {
                statusCode = dbres ? (int)ApiEnum.Status : (int)ApiEnum.Error,
                data       = dbres.ToString()
            };

            return(await Task.Run(() => res));
        }
Exemple #3
0
        /// <summary>
        /// 添加一条记录
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysCodeDto parm)
        {
            var model = new SysCode()
            {
                Guid       = Guid.NewGuid().ToString(),
                Name       = parm.name,
                ParentGuid = parm.parentguid,
                CodeType   = parm.type,
                Sort       = parm.sort,
                Status     = parm.status,
                Summary    = parm.summary,
                AddTime    = DateTime.Now,
                EditTime   = DateTime.Now
            };
            var isok = SysCodeDb.Insert(model);
            var res  = new ApiResult <string>
            {
                statusCode = isok ? (int)ApiEnum.Status : (int)ApiEnum.Error,
                data       = isok ? "1" : "0"
            };

            return(await Task.Run(() => res));
        }