public IEnumerable<Permission> GetPermissions(int memberId, MemberType memberType) { var entity = new PermissionEntity(); var dataAccess = this.EnsureService<IDataAccess>(); var oql = OQL.From(entity) .Select() .Where(p => p.Compare(entity.MemberId, "=", memberId) & p.Compare(entity.MemberType, "=", Convert.ConvertValue<byte>(memberType))) .End(); var entities = dataAccess.Select<PermissionEntity>(oql); return Mapper.Map<IEnumerable<PermissionEntity>, IEnumerable<Permission>>(entities); }
public void SetPermissions(int memberId, MemberType memberType, IEnumerable<Permission> permissions) { if(permissions == null) throw new ArgumentNullException("permissions"); var dataAccess = this.EnsureService<IDataAccess>(); var entities = new List<PermissionEntity>(); foreach(var permission in permissions) { permission.MemberId = memberId; permission.MemberType = memberType; entities.Add(Mapper.Map<Permission, PermissionEntity>(permission)); } var entity = new PermissionEntity(); dataAccess.BeginTransaction(); try { // 清空指定成员的所有权限设置 dataAccess.Execute(OQL.From(entity).Delete().Where(p => p.Compare(entity.MemberId, "=", memberId) & p.Compare(entity.MemberType, "=", Convert.ConvertValue<byte>(memberType))).End()); // 插入指定的权限设置集到数据库中 dataAccess.Insert(entities); // 提交事务 dataAccess.Commit(); } catch(Exception ex) { dataAccess.Rollback(); throw ex; } }