Esempio n. 1
0
 public async Task <IActionResult> AddAdmin([FromBody] SysAdmin parm)
 {
     return(Ok(await _adminService.AddAsync(parm)));
 }
 public async Task <ApiResult <string> > AddAdmin(SysAdmin parm)
 {
     return(await _adminService.AddAsync(parm));
 }
Esempio n. 3
0
        public override async Task <ApiResult <string> > AddAsync(CmsMerchant parm, bool Async = true)
        {
            var res = new ApiResult <string>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                var query = Db.Queryable <CmsMerchant>();

                if (await query.AnyAsync(p => p.out_sub_mch_id == parm.out_sub_mch_id))
                {
                    throw new Exception($"商户子账号【{parm.out_sub_mch_id}】已经存在");
                }

                if (await query.AnyAsync(p => p.name == parm.name))
                {
                    throw new Exception($"商户名称【{parm.name}】已经存在");
                }

                var admin_guid = Guid.NewGuid().ToString();

                var roles = await Db.Queryable <SysRole>()
                            .Where(p => p.Guid == "8dc9b479-216d-415a-9fba-85caedd6c4df")
                            .Select(p => new AdminToRoleList
                {
                    guid = p.Guid,
                    name = p.Name
                })
                            .ToListAsync();

                using var tran = new TransactionScope();

                var adminRes = await sysAdmin.AddAsync(new SysAdmin
                {
                    AddDate            = DateTime.Now,
                    CreateBy           = parm.agent_admin_guid,
                    DepartmentGuid     = null,
                    DepartmentGuidList = null,
                    DepartmentName     = null,
                    Email       = parm.email,
                    Guid        = admin_guid,
                    HeadPic     = null,
                    IsSystem    = false,
                    LoginDate   = null,
                    LoginName   = parm.admin_name,
                    LoginPwd    = "123456",
                    LoginSum    = 0,
                    Mobile      = parm.tel,
                    Number      = null,
                    RoleGuid    = JsonConvert.SerializeObject(roles),
                    Sex         = "-",
                    Status      = true,
                    Summary     = null,
                    TrueName    = parm.name,
                    UpLoginDate = null,
                });

                if (adminRes.statusCode != (int)ApiEnum.Status)
                {
                    throw new Exception(adminRes.message);
                }

                var authenRes = await sysPermissions.ToRoleAsync(new SysPermissions
                {
                    AdminGuid = admin_guid,
                    RoleGuid  = "8dc9b479-216d-415a-9fba-85caedd6c4df",
                    status    = true,
                    Types     = 2
                }, true);

                if (authenRes.statusCode != (int)ApiEnum.Status)
                {
                    throw new Exception(authenRes.message);
                }
                //var relRes = await Db.Insertable(new CmsAdminMerchantRel
                //{
                //    Admin_Guid = admin_guid,
                //    out_sub_mch_id = parm.out_sub_mch_id,
                //    Out_Mch_Id = parm.out_mch_id
                //}).ExecuteCommandAsync();

                //if (relRes <= 0)
                //{
                //    throw new Exception("添加商户代理商关系失败");
                //}

                parm.create_time = DateTime.Now;
                parm.admin_guid  = admin_guid;

                var dbres = await Db.Insertable(parm).ExecuteCommandAsync();

                res.data       = dbres.ToString();
                res.statusCode = (int)ApiEnum.Status;

                tran.Complete();
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }

            return(res);
        }
Esempio n. 4
0
        public override async Task <ApiResult <string> > AddAsync(CmsAgent parm, bool Async = true)
        {
            var res = new ApiResult <string>()
            {
                statusCode = (int)ApiEnum.Error
            };

            try
            {
                var count = 0;
                var query = Db.Queryable <CmsAgent>();

                count = await query.CountAsync(p => p.Name == parm.Name);

                if (count > 0)
                {
                    throw new Exception($"代理商名称【{parm.Name}】已经存在");
                }

                var admin_guid = Guid.NewGuid().ToString();

                var roles = await Db.Queryable <SysRole>()
                            .Where(p => p.Guid == "72171cf0-934d-4934-8e27-ee4f47e9985e")
                            .Select(p => new AdminToRoleList
                {
                    guid = p.Guid,
                    name = p.Name
                })
                            .ToListAsync();

                using var tran = new TransactionScope();

                var adminRes = await sysAdmin.AddAsync(new SysAdmin
                {
                    AddDate            = DateTime.Now,
                    CreateBy           = parm.Curr_Admin_Guid,
                    DepartmentGuid     = null,
                    DepartmentGuidList = null,
                    DepartmentName     = null,
                    Email       = null,
                    Guid        = admin_guid,
                    HeadPic     = null,
                    IsSystem    = false,
                    LoginDate   = null,
                    LoginName   = parm.LoginName,
                    LoginPwd    = "123456",
                    LoginSum    = 0,
                    Mobile      = parm.Tel,
                    Number      = null,
                    RoleGuid    = JsonConvert.SerializeObject(roles),
                    Sex         = "-",
                    Status      = true,
                    Summary     = null,
                    TrueName    = parm.Name,
                    UpLoginDate = null,
                });

                if (adminRes.statusCode != (int)ApiEnum.Status)
                {
                    throw new Exception(adminRes.message);
                }

                var authenRes = await sysPermissions.ToRoleAsync(new SysPermissions
                {
                    AdminGuid = admin_guid,
                    RoleGuid  = "72171cf0-934d-4934-8e27-ee4f47e9985e",
                    status    = true,
                    Types     = 2
                }, true);

                if (authenRes.statusCode != (int)ApiEnum.Status)
                {
                    throw new Exception(authenRes.message);
                }

                parm.Create_Time = DateTime.Now;
                parm.Admin_Guid  = admin_guid;
                parm.Status      = true;

                var dbres = await Db.Insertable(parm).ExecuteCommandAsync();

                res.data       = dbres.ToString();
                res.statusCode = (int)ApiEnum.Status;

                tran.Complete();
            }
            catch (Exception ex)
            {
                res.message = ApiEnum.Error.GetEnumText() + ex.Message;
                Logger.Default.ProcessError((int)ApiEnum.Error, ex.Message);
            }

            return(res);
        }
Esempio n. 5
0
        public async Task <IActionResult> AddAdmin([FromBody] SysAdmin parm)
        {
            parm.CreateBy = await HttpContext.LoginUserId();

            return(Ok(await _adminService.AddAsync(parm)));
        }