示例#1
0
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysAdmin parm)
        {
            var res = new ApiResult <string>
            {
                statusCode = (int)ApiEnum.ParameterError
            };

            try
            {
                //判断用吗是否存在
                var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName);

                if (isExisteName)
                {
                    res.message = "用户名已存在,请更换~";
                    return(res);
                }
                parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd);
                if (string.IsNullOrEmpty(parm.HeadPic))
                {
                    parm.HeadPic = "/themes/img/avatar.jpg";
                }
                parm.Guid    = Guid.NewGuid().ToString();
                parm.AddDate = DateTime.Now;
                if (!string.IsNullOrEmpty(parm.DepartmentGuid))
                {
                    // 说明有父级  根据父级,查询对应的模型
                    var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                    parm.DepartmentGuidList = model.ParentGuidList;
                }
                SysAdminDb.Insert(parm);
                //查询授权表,type=2 更新新的权限值
                //添加新的
                var authorityList = new List <SysPermissions>();
                foreach (var item in parm.RoleList)
                {
                    authorityList.Add(new SysPermissions()
                    {
                        RoleGuid  = item.guid,
                        AdminGuid = parm.Guid,
                        Types     = 2
                    });
                }
                await Db.Insertable(authorityList).ExecuteCommandAsync();

                res.statusCode = (int)ApiEnum.Status;
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(await Task.Run(() => res));
        }
示例#2
0
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysAdmin parm)
        {
            parm.Guid    = Guid.NewGuid().ToString();
            parm.AddDate = DateTime.Now;
            if (!string.IsNullOrEmpty(parm.DepartmentGuid))
            {
                // 说明有父级  根据父级,查询对应的模型
                var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                parm.DepartmentGuidList = model.ParentGuidList;
            }
            SysAdminDb.Insert(parm);
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = "1"
            };

            return(await Task.Run(() => res));
        }
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public new async Task <ApiResult <string> > AddAsync(SysAdmin parm)
        {
            var res = new ApiResult <string>
            {
                statusCode = 200,
                data       = "1"
            };

            try
            {
                //判断用吗是否存在
                var isExisteName = SysAdminDb.IsAny(m => m.LoginName == parm.LoginName);
                if (isExisteName)
                {
                    res.message    = "用户名已存在,请更换~";
                    res.statusCode = (int)ApiEnum.ParameterError;
                    return(await Task.Run(() => res));
                }
                parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd);
                if (string.IsNullOrEmpty(parm.HeadPic))
                {
                    parm.HeadPic = "/themes/img/avatar.jpg";
                }
                parm.Guid    = Guid.NewGuid().ToString();
                parm.AddDate = DateTime.Now;
                if (!string.IsNullOrEmpty(parm.DepartmentGuid))
                {
                    // 说明有父级  根据父级,查询对应的模型
                    var model = SysOrganizeDb.GetById(parm.DepartmentGuid);
                    parm.DepartmentGuidList = model.ParentGuidList;
                }
                SysAdminDb.Insert(parm);
            }
            catch (Exception ex)
            {
                res.message    = ApiEnum.Error.GetEnumText() + ex.Message;
                res.statusCode = (int)ApiEnum.Error;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }
            return(await Task.Run(() => res));
        }
示例#4
0
        /// <summary>
        /// 添加部门信息
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public async Task <ApiResult <string> > AddAsync(SysAdmin parm)
        {
            var res = new ApiResult <string>
            {
                statusCode = (int)ApiEnum.ParameterError
            };

            try
            {
                //判断用吗是否存在
                var isExisteName = await Db.Queryable <SysAdmin>().AnyAsync(m => m.LoginName == parm.LoginName);

                if (isExisteName)
                {
                    res.message = $"用户名【{parm.LoginName}】已经存在";
                    return(res);
                }
                if (parm.RoleList == null || parm.RoleList.Count == 0)
                {
                    res.message = $"请至少选择一个角色";
                    return(res);
                }

                parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd);

                if (string.IsNullOrEmpty(parm.Guid))
                {
                    parm.Guid = Guid.NewGuid().ToString();
                }
                parm.AddDate = DateTime.Now;

                using var tran = new TransactionScope();

                var succ = SysAdminDb.Insert(parm);

                var authorityList = parm.RoleList
                                    .Select(p => new SysPermissions
                {
                    RoleGuid  = p.guid,
                    AdminGuid = parm.Guid,
                    Types     = 2
                }).ToList();

                await Db.Insertable(authorityList).ExecuteCommandAsync();

                tran.Complete();

                //var rel = await Db.Queryable<CmsAdminMerchantRel>().Where(p => p.Admin_Guid == parm.CreateBy).FirstAsync();
                //if (rel != null)
                //{
                //    CmsAdminMerchantRelDb.Insert(new CmsAdminMerchantRel
                //    {
                //        Admin_Guid = parm.Guid,
                //        Out_Mch_Id = rel.Out_Mch_Id,
                //        out_sub_mch_id = rel.out_sub_mch_id
                //    });
                //}

                res.statusCode = (int)ApiEnum.Status;
                res.data       = parm.Guid;
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }

            return(res);
        }