Exemple #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();
                    }
                }
            }
        }
Exemple #2
0
        public Model.StaffInfo InsertUpdateStaff(Model.StaffInfo staffInfo)
        {
            try
            {
                var config = new MapperConfiguration(cfg => {
                    cfg.CreateMap <Model.StaffInfo, Entity.StaffInfo>();
                });
                IMapper mapper          = config.CreateMapper();
                var     staffInfoEntity = mapper.Map <Model.StaffInfo, Entity.StaffInfo>(staffInfo);

                if (staffInfoEntity.StaffInfoId == 0)
                {
                    Entity.UserProfile userProfile = new Entity.UserProfile
                    {
                        FirstName     = staffInfoEntity.FirstName,
                        LastName      = staffInfoEntity.LastName,
                        Email         = staffInfoEntity.Email,
                        Password      = Utilities.CreateRandomPassword(8),
                        ContactNumber = staffInfoEntity.MobileNumber,
                        RoleId        = (int)_schoolContext.Roles.Where(r => r.RoleName == "Staff").Select(s => s.RoleID).FirstOrDefault(),
                        UserId        = 0
                    };
                    _schoolContext.UserProfile.Add(userProfile);
                    _schoolContext.SaveChanges();
                    if (userProfile.UserId > 0)
                    {
                        staffInfoEntity.UserId   = userProfile.UserId;
                        staffInfoEntity.IsActive = true;
                        _schoolContext.StaffInfo.Add(staffInfoEntity);
                        _schoolContext.SaveChanges();
                        staffInfo.StaffInfoId = staffInfoEntity.StaffInfoId;
                        staffInfo.IsActive    = staffInfoEntity.IsActive;
                        staffInfo.UserId      = userProfile.UserId;
                    }
                }
                else
                {
                    _schoolContext.Entry(staffInfoEntity).State = EntityState.Modified;
                    _schoolContext.SaveChanges();
                }

                return(staffInfo);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #3
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
                        });
                    }
                }
            }
        }