Example #1
0
        public async Task EditRoleAsync(EditRoleModel model)
        {
            if (string.IsNullOrEmpty(model.Code))
            {
                throw new InvalidOperationException("代码为空");
            }
            if (string.IsNullOrEmpty(model.Name))
            {
                throw new InvalidOperationException("名称为空");
            }
            if (await _roleRepository.CountAsync(m => m.ID != model.ID && m.Code == model.Code) > 0)
            {
                throw new InvalidOperationException("代码重复");
            }
            Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(model.ID);

            if (roleFromDB == null)
            {
                throw new InvalidOperationException("角色不存在");
            }
            model.CopyProperties(roleFromDB);
            await EditRoleActionAuthorities(roleFromDB, model.ActionAuthorityIDs);
            await EditRoleAPIAuthorities(roleFromDB, model.APIAuthorityIDs);
            await EditRoleWebMenuAuthorities(roleFromDB, model.WebMenuAuthorityIDs);

            _authorityUnitOfWork.RegisterEdit(roleFromDB);
            await _authorityUnitOfWork.CommitAsync();

            _roleRepository.ClearCache();
        }
        public async Task EditRoleAsync(EditRoleModel model)
        {
            Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(model.ID);

            if (roleFromDB == null)
            {
                throw new InvalidOperationException("角色不存在");
            }
            model.CopyProperties(roleFromDB);
            roleFromDB.UpdateTime = DateTime.Now;
            await EditRoleWebMenus(roleFromDB, model.WebMenuIDs);

            _authorityUnitOfWork.RegisterEdit(roleFromDB);
            await _authorityUnitOfWork.CommitAsync();
        }