Exemplo n.º 1
0
        public T one(long id, bool withIncludes = true, bool throwException = true)
        {
            if (!policy.checkShow(id))
            {
                throw new UnauthorizedException("You do not have permission to view requested resource.");
            }

            var reader = DB.all(this.tableName, new DbParams(new DbParam[] {
                new DbParam("id", id, this.transformer.getParamType("id")),
            }));

            if (!reader.HasRows && throwException)
            {
                throw new ItemNotFoundException();
            }

            if (!reader.HasRows)
            {
                return(null);
            }

            reader.Read();
            var transformed = transformer.transform(reader);

            reader.Close();

            return(withIncludes ? this.addIncludes(transformed) : transformed);
        }