Exemplo n.º 1
0
        /// <summary>
        /// 增加多个职员
        /// </summary>
        /// <param name="staffInfos">职员信息</param>
        /// <param name="operatorId">操作员id</param>
        /// <param name="key">秘钥</param>
        /// <param name="originalRoleName">角色名</param>
        /// <returns></returns>
        public async Task AddGroupStaff(List <StaffBsicInfoDto> staffInfos, Guid operatorId, string key, string originalRoleName)
        {
            List <Guid> modifyIds = new List <Guid>();

            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                foreach (var staffInfo in staffInfos)
                {
                    var staff = new Model.StaffInfo()
                    {
                        Name      = staffInfo.Name,
                        Tel       = staffInfo.Tel,
                        Password  = StringEncryptAndDecrypt.AESEncrypt(staffInfo.Tel, key),
                        Email     = staffInfo.Email,
                        Address   = staffInfo.Address,
                        IdCard    = staffInfo.IdCard,
                        ImagePath = staffInfo.ImagePath,
                        SectionId = staffInfo.SectionId,
                        Position  = staffInfo.Position
                    };
                    await staffInfoService.CreateAsync(staff, false);

                    modifyIds.Add(staff.Id);
                }
                await staffInfoService.Save();
            }

            using (IAccountOperateLogService accountOperateLogService = new AccountOperateLogService())
            {
                using (IStaffPowerInfoService staffPowerInfoService = new StaffPowerInfoService())
                {
                    using (IRoleInfoService roleInfoService = new RoleInfoService())
                    {
                        foreach (var modifyId in modifyIds)
                        {
                            await accountOperateLogService.CreateAsync(new Model.AccountOperateLog()
                            {
                                OperatorId  = operatorId,
                                ModifiedId  = modifyId,
                                OPerateType = ('1').ToString()
                            }, false);

                            //初始权限
                            await staffPowerInfoService.CreateAsync(new Model.StaffPowerInfo()
                            {
                                StaffId = modifyId,
                                RoleId  = (await roleInfoService.GetAll().Where(p => p.Name == originalRoleName).FirstAsync()).Id //得到对应权限的Id
                            }, false);
                        }

                        //一起更新
                        await accountOperateLogService.Save();

                        await staffPowerInfoService.Save();
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 增加一个职员
        /// </summary>
        /// <param name="staffInfo">职员信息</param>
        /// <param name="operatorId">操作员id</param>
        /// <param name="key">秘钥</param>
        /// <param name="originalRoleName">角色名</param>
        /// <returns></returns>
        public async Task AddOneStaff(StaffBsicInfoDto staffInfo, Guid operatorId, string key, string originalRoleName)
        {
            using (IStaffInfoService staffInfoService = new StaffInfoService())
            {
                var staff = new Model.StaffInfo()
                {
                    Name      = staffInfo.Name,
                    Tel       = staffInfo.Tel,
                    Password  = StringEncryptAndDecrypt.AESEncrypt(staffInfo.Tel, key),
                    Email     = staffInfo.Email,
                    Address   = staffInfo.Address,
                    IdCard    = staffInfo.IdCard,
                    ImagePath = staffInfo.ImagePath,
                    SectionId = staffInfo.SectionId,
                    Position  = staffInfo.Position
                };
                await staffInfoService.CreateAsync(staff);

                using (IAccountOperateLogService accountOperateLogService = new AccountOperateLogService())
                {
                    await accountOperateLogService.CreateAsync(new Model.AccountOperateLog()
                    {
                        OperatorId  = operatorId,
                        ModifiedId  = staff.Id,
                        OPerateType = "1"
                    });
                }

                //初始权限
                using (IStaffPowerInfoService staffPowerInfoService = new StaffPowerInfoService())
                {
                    using (IRoleInfoService roleInfoService = new RoleInfoService())
                    {
                        await staffPowerInfoService.CreateAsync(new Model.StaffPowerInfo()
                        {
                            StaffId = staff.Id,
                            RoleId  = (await roleInfoService.GetAll().Where(p => p.Name == "一级权限").FirstAsync()).Id
                        });
                    }
                }
            }
        }